从现有数据库创建模型时,Entity Framework 4.0生成只读模型 [英] Entity Framework 4.0 generating read only model when I create model from existing database

查看:104
本文介绍了从现有数据库创建模型时,Entity Framework 4.0生成只读模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义的ado.net提供程序,并且正在使用该提供程序,我正在Visual Studio 2010中集成实体框架支持。我正在创建所有可能的映射并从数据库中读取表对象的所有相关元数据。对于我的测试,一个表包含主键和其他字段。当我使用该表从数据库创建模型时,我得到一个包含所有列映射和所有内容的模型,但同时我还会收到以下错误消息:

I am working on a custom ado.net provider and using that provider I am integrating Entity Framework support in Visual Studio 2010. I'm creating all possible mapping and reading all the related metadata from database for table objects. For my test, a table contains primary keys and and other fields. When I create a model from database using this table and I get a model with all column mappings and everything but I also get error messages that follow:


模型已生成警告或错误。
请参阅错误列表以获取更多详细信息。必须先解决这些问题,然后再运行您的应用程序。
从数据库加载元数据花费了00:00:11.4799371。
生成模型的时间为00:00:04.2751189。
将连接字符串添加到App.Config文件中。
编写.edmx文件花费了00:00:00.0005060。

The model was generated with warnings or errors. Please see the Error List for more details. These issues must be fixed before running your application. Loading metadata from the database took 00:00:11.4799371. Generating the model took 00:00:04.2751189. Added the connection string to the App.Config file. Writing the .edmx file took 00:00:00.0005060.

如果我使用XML编辑器打开.edmx文件,我看到以下错误:

If I open the .edmx file with XML editor, I see the following error:

<!--Errors Found During Generation:
  warning 6002: The table/view 'sqlfire.APP.CUSTOMERS' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.
  -->

它还为表添加了带有SELECT ...语句的DefiningQuery。

It also added a DefiningQuery with a SELECT ... statement for the table.

我正围成一圈寻找解决方案,并急切地寻求有关此问题的帮助。

I am going in a circle to find a solution and desperately looking for some help on this issue.

推荐答案

错误消息中的表格/视图之一似乎没有主键 EF 在每个表中都需要一个 Primary-Key ,以便生成实体密钥。

From the error message looks like one of your table/view doesn't have a Primary-Key. EF needs a Primary-Key in every table in order to generate Entity keys.

您也许仍然可以运行应用程序,但是我强烈建议您按照警告添加主键。

You may still be able to run your application, but I strongly suggest you add primary keys as warned.

这篇关于从现有数据库创建模型时,Entity Framework 4.0生成只读模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆