Only when we start to write code in, we will realize some pactical scenarios we should have preferred as programming language. One such case happened to me, when i was trying to write something in LINQ along with But after a lot of research and search, i achieved my goal with itself. Sharing are those below:

To remove an item from Ilist collection using LINQ and

Dim validLineItems As IList = ‘Get the collection of data from db or any source as Ilist
Dim itemToRemove As Object = (From p In validLineItems Where p.UNIQUEID = CType(“Unique ID in hand”, Integer)) .SingleOrDefault()

Now the same ‘validLineItems’ contains the collection after teh removed item, which you can bind straightaway to any databinding control (dropdown, grid etc)

To remove an item from XML string, using LINQ and

Dim xd As XDocument = XDocument.Parse(xmlInputSource) ‘xmlInputSource is a well-formatted xml
Dim itemsToRemove = (From element In xd.Root.Elements(“PARENTNODE”) Where element.Attribute(“CHILDNODE”).Value = ‘value in hand’)

xmlInputSource, PARENTNODE, CHILDNODE are values you have to replace

2 thoughts on “LINQ samples to be used with”

Leave a Reply