none
EF 4.1 and asp.net binding RRS feed

  • Question

  • Hi there!

    I just got Entity Framework 4.1 and updated my model to use it. The thing is that the code that was working ok is not now.

        public static IEnumerable<Employee> GetEmployees()
        {
          IntranetModelContainer db = new IntranetModelContainer();
          return db.Entities.OfType<Employee>();
        }
    

    When I try to call that method, I get this exception:

    Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data. For WPF bind to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList().

     

    I've searched and found this http://social.msdn.microsoft.com/Forums/en-NZ/adodotnetentityframework/thread/65e5ed34-751e-4bd9-90a0-ae83ac81ba6c guy with the same problem. I try to use his solution, but I did not have a Load method to call anywhere.

     

    Well, how do I bind a DataGrid to a EntityFramework object now?

    Thanks

    Friday, August 12, 2011 7:56 PM

Answers

  • The "Load" method that the exception was asking me to call was on a freaking different namespace!!

     

    I've imported (using System.Data.Entity;) and changed my method and it worked

    public static IEnumerable<Employee> GetEmployees()
        {
          IntranetModelContainer db = new IntranetModelContainer();
          db.Entities.OfType<Employee>().Load();
          return db.Entities.Local.OfType<Employee>();
        }


    Hope it helps!

    Thanks

    • Marked as answer by Lucas Phillip Tuesday, August 16, 2011 7:26 PM
    Tuesday, August 16, 2011 7:12 PM

All replies

  • Hello,

    Based on your description and code snippets, we didn't reproduce your question on my side. Could you please provide the demo application and detailed steps to us to analyze your question? You can send it to me here. v-xugong@microsoft.com

    Thanks,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 16, 2011 11:48 AM
  • The "Load" method that the exception was asking me to call was on a freaking different namespace!!

     

    I've imported (using System.Data.Entity;) and changed my method and it worked

    public static IEnumerable<Employee> GetEmployees()
        {
          IntranetModelContainer db = new IntranetModelContainer();
          db.Entities.OfType<Employee>().Load();
          return db.Entities.Local.OfType<Employee>();
        }


    Hope it helps!

    Thanks

    • Marked as answer by Lucas Phillip Tuesday, August 16, 2011 7:26 PM
    Tuesday, August 16, 2011 7:12 PM