映射模型中的片段问题 [英] Mapping fragments problem in a model

查看:43
本文介绍了映射模型中的片段问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我创建了一个模型,我想使用相同的"项目"。通过相同的id字段的不同类型的元素。类似的东西:

I created a model where i would like to use the same "Item" element for different types through the same id field. something like that:

项目

id

name

id_relation

id_relation

id_type

 

根据类型, id_relation 将与不同的表相关联,例如

Depending of the type, the id_relation is gonna be linked with different tables, for instance

如果类型是"进程",则那么 id_relation
将被链接到表格"Process" (该关系将在"过程"表格中的
id_relation
id 之间),但如果类型是"风险",那么
id_relation
将与表格"Risks"相关联。我没有在我的数据库模型(1:1)中使用标识关系,因为相同的"过程"是(或风险),可以链接几个项目。

if is the type is "Process" then id_relation is gonna be linked the table "Process" (the relation gonna be between id_relation and id in "Process" table), but if the type is "Risk" then the id_relation is gonna be linked with the table "Risks". I didn't use an identification relation in my database model (1:1) because the same "Process" (or Risk), can be linked with several items.

在数据库模型中,一切看起来都不错,(几个表与表项链接使用相同的
id_relation 字段。。

In the database model everything looks OK, (several tables are linked with the table Items using the same id_relation field).

问题在于,当我创建实体模型时,我收到以下错误:

The problem is that when I create the entity model, I'm getting the following error:

" 错误3007:映射片段中的问题从第3381,3620行开始:非主键列[id_relation]正在两个片段中映射到不同的概念侧属性 - 数据不一致是可能的,因为相应的
概念方属性可以独立修改

我得到相同的错误5次(我有5个不同的表链接到"商品"在"商品"中使用相同的
id_relation 字段。)

I get the same error 5 times (I have 5 different tables linked to "Item" using the same id_relation field in "Item").

任何关于如何才能的想法我解决了这个问题????

Any idea about how can I fix this problem????

 

推荐答案

是的,这不是允许犯罪可以在EF中独立修改FK值,一次更改可以覆盖另一个。您必须使用DefiningQueries(将它们视为SSDL中定义的视图)为这些不同的关系创建不同的列
,映射回数据库中的单个列。您必须使用SSDL或存储过程中定义的函数进行更新。

Yes, this is not allowed since the FK values can be independently modified in EF and one change can overwrite another. You have to use DefiningQueries( think of them as views defined in SSDL) to create different columns for these different relationships that map back to the single column in the database. You would have to use Functions defined in SSDL or stored procedures for updates.

谢谢

Srikanth


这篇关于映射模型中的片段问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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