日期:2014-05-17  浏览次数:20472 次

EF 在生成ado.net entity Data Model 遇到的问题
申明,本人菜鸟,依葫芦画样出现的问题:
在使用ado.net entity Data Model 自动生成
Model.Designer.sc文件中有:
public partial class NorthwindEntities : ObjectContext
{这里有public ObjectSet<Employee> Employees{get...}
Model.Context.cs文件中有:
public partial class NorthwindEntities : DbContext
{public DbSet<Employee> Employees { get; set; }}

页面代码:
NorthwindEntities db = new NorthwindEntities();
gridView1.DataSource=db.Employees;
gridView.DataBind();
运行出错:
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(). 
猜测:同时有ObjectSet<>和DbSet<>类型的Employees,db.Employees选择了DbSet<>,
删掉public partial class NorthwindEntities : DbContext
{public DbSet<Employee> Employees { get; set; }}
然后就正常!
问题:DbSet<>怎么用?本人菜鸟。谢谢各位大大指点
entity ADO.NET Linq?to?entity Linq?to?entities

------解决方案--------------------