In c# MVC, I need to get the following “result” (var) in the data table.
var allCompanies = objentity.ExecuteFunction<SearchAvailEmployees_Result>("SearchAvailEmployees", lstParam.ToArray())
.ToList();
var result = from c in allCompanies select new[] {
c.LastName,
c.FirstName,
c.Phone,
c.City,
c.PositionApplied,
c.Status,
Convert.ToString(c.CallDate.Value.ToShortDateString()),
Convert.ToString(c.CellOrPager),
c.Gender
};
I tried the following code but it won’t works. It gives the error as
“Cannot implicitly convert type ‘System.Collections.Generic.IEnumerable’ to ‘System.Collections.Generic.IEnumerable’. An explicit conversion exists (are you missing a cast?)”
IEnumerable<DataRow> query = from c in allCompanies select new[] {
c.LastName,
c.FirstName,
c.Phone,
c.City,
c.PositionApplied,
c.Status,
Convert.ToString(c.CallDate.Value.ToShortDateString()),
Convert.ToString(c.CellOrPager),
c.Gender
};
DataTable boundTable = query.CopyToDataTable<DataRow>();
Any alternate solution to save the linq query result in data table?
This is how I do it:
First I declare a new
DataTableand add columns, in this :Now I execute the desired query:
Now I simply iterate through the query and fill a
DataTable:Still in my queries I am using ‘join’-statements.