Recently some one asked me how should I need to convert a DataTable to an List of Entity Object. Let me Explain in detail below…
Let say we have following Entity Class called Testimonial with two properties i.e.., Comment and Commentedby here Comment is the property where we have the actual comment by the User and Commentedby is the property to store the name of the
User who commented it.
Now we need to get these Testimonial data from data source it may be from Database / XML file / CSV File etc.., we use XML file for this example . Now using linq we Enumerate the collection of dataRows in the datatable and create a list of Testimonials as
List<Testimonial> lstTestimonial =
strpath = System.IO.Path.Combine(AppDomain.CurrentDomain.GetData(“DataDirectory”).ToString(), “Testimonials.xml”);
&& ds.Tables.Count > 0)
= (from r
Note this is the best way to convert because due to strong data-type using Field Method, we can rectify any type conversion issues at Compile time.
Hope this short explanation (due to insufficient time) Helps you… Please comment me in any case…
Helpfull article thanks :)