Visual Studio 2013 and Entity Framework

后端 未结 1 377
[愿得一人]
[愿得一人] 2021-01-05 15:02

I\'m using VS 2013 and SQL Svr 2012 and trying use EF to populate a gridview. As this is a very simple test, I have just one table with a key and a couple of data fields.

相关标签:
1条回答
  • 2021-01-05 15:25

    Unfortunately, the EntityDataSource control does not work with the latest version of Entity Framework, EF6. Hopefully the control gets an update in a future update version of VS or EF, but for now you can't use the two together.

    There are a few solutions / alternatives:

    1. Drop back to EF 5. In order to do this, delete the .edmx and .tt files from the App_Code folder, delete the EF assemblies from the Bin folder, and remove the references to EF from web.config. Then rebuild the site, add a new ADO.NET Entity Model and choose version 5 in the Choose Your Version dialog. Then delete the .tt files from the App_Code folder, open the EDMX diagam, right-click an empty spot and on the Properties Grid set Code Generation Strategy to Legacy ObjectContext. Then rebuild again, and it should work.

    2. Use Model Binding. This is really the recommended solution. The Microsoft / EF team recommends people to stay away from the EntityDataSource control and only use it for Dynamic Data web sites, Model Binding is the preferred solultion. It's pretty clean and straight forward to use, and gives you a lot of control over your queries and object updates. For more info about Model Binding, check out: http://www.asp.net/web-forms/tutorials/data-access/model-binding/retrieving-data

    0 讨论(0)
提交回复
热议问题