实体框架-按类型继承的表-现有数据库 [英] Entity Framework - Table Per Type Inheritance - Existing Database

查看:95
本文介绍了实体框架-按类型继承的表-现有数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为现有数据库的Entity框架实现Table Per Type继承.

I want to implement Table Per Type inheritance with Entity framework for an existing database.

数据库:

ImageParagraphs的继承工作完美,但是由于主键(ParagraphID; ParagraphID + LinkID)不同,我无法使用LinkListParagraph进行每个类型的表"继承:

The inheritance for ImageParagraphs works perfect, but I am not able to make a Table Per Type inheritance with LinkListParagraph because of the different primary keys (ParagraphID; ParagraphID+LinkID):

错误1错误3003:映射片段的问题从第113行开始:EntitySet段的所有键属性(Paragraphs.ParagraphID)必须映射到表LinkListParagraph的所有键属性(LinkListParagraph.LinkID,LinkListParagraph.ParagraphID) . C:\ Users \ buc \ Documents \ Visual Studio 2008 \ Projects \ ParagraphTest \ ParagraphTest \ ParagraphModel.edmx 114 15 ParagraphTest

Error 1 Error 3003: Problem in Mapping Fragment starting at line 113: All the key properties (Paragraphs.ParagraphID) of the EntitySet Paragraphs must be mapped to all the key properties (LinkListParagraph.LinkID, LinkListParagraph.ParagraphID) of table LinkListParagraph. C:\Users\buc\Documents\Visual Studio 2008\Projects\ParagraphTest\ParagraphTest\ParagraphModel.edmx 114 15 ParagraphTest

是否有可能在不更改数据库的情况下解决此问题?

Is there a possiblity to solve this problem without changes to the database?

我想做的是这样的:

推荐答案

一种方法可能是对实体框架说谎有关主键的内容.这将需要进入EDMX中的商店映射并更改主键标志.但是请意识到,如果执行此操作,则每次执行更新时,数据库更新模型"向导都会尝试修复"您的映射.

One way might be to lie to the Entity Framework about the primary key. This would require going into the store mapping in the EDMX and changing the primary key flags. Realize, however, that if you do this then the Update Model from Database wizard will try to "fix" your mapping every time you do an update.

另一种方法是在数据库中创建视图并映射该视图而不是表.

Another way would be to create a view in your database and map the view instead of the table.

这篇关于实体框架-按类型继承的表-现有数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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