0

I am trying to write a simple save and load operation using EDMX in Visual Studio 2008.

This is my load method:

    public static DataTable LoadData()
    {

    using (testEntities context = new testEntities())
      { 

              testEntities temp = new testEntities();
        DataTable dt = new DataTable();

       IQueryable<DataRow> empResults = (from c in temp.emplyee
                                          select c).AsQueryable();


       }


        return dt;
    }

However I receive the following error:

Cannot implicitly convert type 'System.Linq.IQueryable<>' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?)

I am not able to find any exact link for this conversion.

user3487944
  • 267
  • 4
  • 9
  • 22

2 Answers2

0

Try this

 IQueryable<DataRow> empResults = (from c in temp.emplyee
                                   select c).Cast<DataRow>().AsQueryable();

But ensure that temp.emplyee is DataRow


So if you are using EF you need to use generated models and context, not adapters and dataTable

Veikedo
  • 1,453
  • 1
  • 18
  • 25
0

You cannot cast that directly, CopyToDataTable should help you though:

DataTableExtensions.CopyToDataTable<T> Method (IEnumerable<T>)

http://msdn.microsoft.com/en-us/library/bb396189.aspx

Or you can implement a custom method to populate DataRow columns with properties of you entity.

Andrew
  • 3,648
  • 1
  • 15
  • 29