我如何正确设置在实体框架4 Entitydesigner两个对象之间的关联? [英] How do I correctly set an association between two objects in the Entity Framework 4 Entitydesigner?
问题描述
有关一个新的项目,我想先创建我的商业课程,后来创建真正的数据库表。因此,我使用的是实体框架4设计。 A创建一个新的ADO.Net实体数据模型的文件,扩展的.edmx。
For a new project I'm trying to create my business classes first and create the real database tables later. Therefore I'm using the Entity Framework 4 Designer. A created a new "ADO.Net Entity Data model" file, with the extension .edmx.
我创建了两个实体:结果
I created two Entities:
我要添加产品之间的1到NC关系 - >组。如果我创建了MSSQL数据库首先,我会加入一列IDGroup到表产品和参考Product.IDGroup到Group.IDGroup。据我所看到的,我不能在设计中添加这种关联,如果我添加一个名为IDGroup新属性的产品实体
I want to add a 1 to nc relation between Product -> Group. If I'd created the MSSQL database first, I would have added a column IDGroup to the Table Product and referenced Product.IDGroup to Group.IDGroup. As far as I can see, I can't add such association in the designer if I add a new Property called IDGroup to the Product Entity
这是我怎么加的映射:
This is how I add the mapping:
这会导致:结果
Which results in:
现在的部分是什么这个问题大概是:如果我从一个现有的MSSQL数据库的EDMX文件中添加两个表,我会得到编译错误:
Now the part what this question is about: If I add two tables from an existing MSSQL database to the edmx file, I'll get the compile error:
Error 3027: No mapping specified for the following EntitySet/AssociationSet - GroupSet, ProductSet
这是什么意思的错误和我必须做什么来解决这个问题?
如果我删除这两个表,我会收到一个警告而不是:
What does that error mean and what must I do to fix this? If I delete those two tables, I'll receive a warning instead:
Error 2062: No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer myContainer.
有个声音告诉我,我做的这一切错误的,这仅仅是基本的东西。我该怎么办呢吧?
Something tells me, I'm doing this all wrong and this is just basic stuff. How can I do it right?
推荐答案
我只是碰到了这个自己&放大器;当我GOOGLE了它(我打你的问题)。
I just ran into this myself & when I Googled it (I hit your question).
我能够双击设计器中的线(关联线)。在属性填写那里,我得到它的工作。
I was able to double click on the line (association line) in the designer. Fill in the properties there and I got it working.
我也不得不关闭VS和重新打开它得到一些报告的错误中去了......
I also had to close VS and re-open it to get some of the errors reported to go away...
不能说这是正确的答案 - 只是摸索周围,并似乎得到的结果。
Can't say this is the correct answer - just fumbling around and seeming to get results.
这篇关于我如何正确设置在实体框架4 Entitydesigner两个对象之间的关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!