I have a Linq expression which I’d like to insert to a ADO.NET datatable.
I would like to know the name of the fields from the query in order to set the datatable name.
Here is an example of my code:
var result=from item in context.table
select new{
field1=... ,
field2=... ,
field3=...
};
What I’d like to do is to set the tables name.
Datatable.Columns.Add("field1"); .. etc
I tried to do it manually but I believe there should be an elegant solution for it.
Thanks
By making use of reflection you can extract the names of the properties of your anonymous type created in the LINQ expression.