Reputation:
I have been trying to fill up a datatable with the LINQ results so I can iterate though the DT and print out the needed data but no matter how I try it cant convert the anonomus type into a datatable.
The LINQ I am using is:
using (var db = new SiteNavigation())
{
dtNavData= (from n in db.Navigation
join st in db.SectionTranslations
on n.SectionID equals st.Section.SectionID
where n.Category == Category && st.CultureID == CultureID
orderby n.Position ascending
select new
{
LinkAddress = st.Section.Type + "/" + st.Section.RouteName,
st.Title
}).ToList();
}
Is there some way to get the results into a datatable or any other object so I can step though it row by row and process the data?
Upvotes: 0
Views: 1077
Reputation: 12375
you don't have to create a DataTable
, if all that you want is to iterate through the result of your linq query
var myResult = (from n in db.Navigation
join st in db.SectionTranslations
on n.SectionID equals st.Section.SectionID
where n.Category == Category && st.CultureID == CultureID
orderby n.Position ascending
select new
{
LinkAddress = st.Section.Type + "/" + st.Section.RouteName,
st.Title
}).ToList();
foreach(var item in myResult)
{
string linkAddrs = item.LinkAddress;
string title = item.Title;
}
Upvotes: 1