I'm trying the first solution mentioned in - http://forums.asp.net/t/1320587.aspx , to return the linq result to a dataset. But I dont get the 'GetCommand' property after 'mdb'. The error says MedianEntities does not contain a definition for 'GetCommand'. Are you missing an assembly.
What else should I include to fix this.
public DataSet GetAllRecords()
{
DataSet ds = new DataSet();
MEDIANEntities mdb = new MEDIANEntities();
var query = (from j in mdb.tblCountries
orderby j.CountryName ascending select j);
SqlCommand cmd = (SqlCommand)mdb.GetCommand(query); //error here
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
return ds;
}
Using .Netframework 4.0 and Entity Model
DataContext and GetCommand is for LINQ-To-SQL, you want to work with LINQ-To-Entity.
There are multiple issues, your entities MEDIANEntities could be DbContext, the GetCommand is on DataContext class.
Another issue is that your "query" is not an IQueryable, need to remove your .AsEnumerable() from your query.
You can use
CopyToDataTable<DataRow>()
on yourquery
instead to accomplish what you need. http://msdn.microsoft.com/en-us/library/bb396189.aspxAnother option, which should work but might be hacky, as you are mixing DataContext (linq-to-sql) with (linq-to-entity). Something like that:
More info on GetCommand:
DataContext.GetCommand
Namespace: System.Data.Linq
Assembly: System.Data.Linq (in System.Data.Linq.dll)
http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.getcommand.aspx