VB.NET switching from ADO.NET to LINQ
- by Cj Anderson
I'm VERY new to Linq. I have an application I wrote that is in VB.NET 2.0. Works great, but I'd like to switch this application to Linq. I use ADO.NET to load XML into a datatable. The XML file has about 90,000 records in it. I then use the Datatable.Select to perform searches against that Datatable. The search control is a free form textbox. So if the user types in terms it searches instantly. Any further terms that are typed in continue to restrict the results. So you can type in Bob, or type in Bob Barker. Or type in Bob Barker Price is Right. The more criteria typed in the more narrowed your result. I bind the results to a gridview.
Moving forward what all do I need to do? From a high level, I assume I need to:
1) Go to Project Properties -- Advanced Compiler Settings and change the Target framework to 3.5 from 2.0.
2) Add the reference to System.XML.Linq, Add the Imports statement to the classes.
So I'm not sure what the best approach is going forward after that. I assume I use XDocument.Load, then my search subroutine runs against the XDocument. Do I just do the standard Linq query for this sort of repeated search? Like so:
var people =
from phonebook in doc.Root.Elements("phonebook")
where phonebook.Element("userid") = "whatever"
select phonebook;
Any tips on how to best implement?