Nan*_*ada 1 sql-server asp.net-mvc entity-framework primary-key visual-studio-2008
我试图"授权"一些外部表(我不管理)以便在MVC应用程序中使用它,原则上我对尝试(VS2008输出)并不是非常成功:
错误列表 [0错误] [0警告] [1消息]
描述
The table/view 'DATABASE.dbo.table' does not have a primary key defined and no valid primary key could be inferred.
This table/view has been excluded. To use the entity you will need to review your schema, add the correct keys and uncomment it.
Run Code Online (Sandbox Code Playgroud)
文件
C:\Documents and Settings\%USERNAME%\My Documents\Visual Studio 2008\Projects\MVC_Entity_Test\MVC_Entity_Test\Models\EmployeesDataModel.edmx
Run Code Online (Sandbox Code Playgroud)
线
0
Run Code Online (Sandbox Code Playgroud)
柱
1
Run Code Online (Sandbox Code Playgroud)
项目
MVC_Entity_Test
Run Code Online (Sandbox Code Playgroud)
产量
显示输出:实体数据模型
Added the connection string to Web.Config.
Successfully registered the assembly 'System.Data.Entity, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' in Web.Config.
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 database took 00:00:06.2809306.
Generating model took 00:00:03.0359078.
Writing out the EDMX file took 00:00:00.0230083.
Added the connection string to Web.Config.
Successfully registered the assembly 'System.Data.Entity, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' in Web.Config.
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 database took 00:00:12.3208290.
Generating model took 00:00:03.6914563.
Writing out the EDMX file took 00:00:02.1670689.
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,是否绝对必须在源表上声明PK 以正确映射它作为ASP.NET实体?
注意:我不希望这个帖子成为关于伟大的,标准驱动的,学术支持的数据库建模的论文,事情是,我必须处理来自某个地方的某个视图的外部表,它来自某个地方的某个表等等,所以我真的无法控制它.关键是我只想让我的一面完成.
实体框架是一个映射框架,因此需要一种方法将每一行唯一映射到一个对象.这需要某种形式的唯一标识符,用于生成SQL DML语句,以便可以修改行.
在您的情况下,如果列的组合不包含唯一标识行的NULL,则可以手动将必要的信息添加到edmx文件中.此MSDN页面将描述手动将对象添加到edmx的基础知识,http://msdn.microsoft.com/en-us/library/bb399785.aspx.请记住,它只是一个可以编辑的XML文件.
| 归档时间: |
|
| 查看次数: |
3622 次 |
| 最近记录: |