本文介绍了在这种情况下,我如何联系我的实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[]



链接的图片显示做什么数据模型,我想通过使用Entity Framework Code First来实现。



另一个例子,有点复杂,假设这些:



- 接口:IPhone,IEmail ,IPerson和IEnterprise

- 实体:实施IEmail的电子邮件,实施IPhone的电话,实施IPerson的学生,用户和供应商以及实施IEnterprise的客户,供应商和办公室;

- 关系角色:

1.来自IPerson和IEnterprise的所有实体可以有零个或多个电话。

2.每个电话只有一个所有者。

3.与电话的每个关系必须存储在相关的链接表中,而不是直接存储在电话的表格上。

4.删除IEnterprise将删除子记录。

5.删除IPerson将删除除了不会删除子记录的用户以外的子记录。

6.查询电话时,我需要获得所有者,无论它是什么类型。 />


所以,我的问题是:如何使用实体解释我的实体Framework 6 Code First / FluentAPI?



提前谢谢。

The basic idea [^]

The linked image shows "what to do" in a data model, and I want to do it by using Entity Framework Code First.

As another example, a bit more complex, suppose these:

- Interfaces: IPhone, IEmail, IPerson and IEnterprise
- Entities: Email that implements IEmail, Phone that implements IPhone, Student, User and Vendor that implements IPerson and Customer, Supplier and Office that implements IEnterprise;
- Relationship Roles:
1. All entities from IPerson and IEnterprise can have zero or many Phones.
2. Each Phone have only one owner.
3. Each relation with Phone must be stored in a related link table and not directly on Phone's table.
4. On delete for IEnterprise will delete child records.
5. On delete for IPerson will delete child records except User that will not delete child records.
6. When querying Phones, I'll need to get the owner, whatever kind it is.

So, my question is: How to relate my entities as explained using Entity Framework 6 Code First/FluentAPI ?

Thank you in advance.

推荐答案

OwnerType (OTypeID INT IDENTITY(1,1), ODescription NVARCHAR(155))
Owners (OwnerID INT IDENTITY(1,1), OName NVARCHAR(155), OSurName NVARCHAR(155), ONickName NVARCHAR(155), OBirthDay DATETIME, OTypeID INT (FK - reference to OwnerType table))
Phones (PhoneID INT IDENTITY(1,1), PNumber (?), PCompany (?), PAreaCode(?))
Owners_Phone (OwnerID INT (FK - reference to Owners table), PhoneID INT (FK - reference to Phones table))





注意:这是唯一的建议; )



Note: it's only suggestion ;)



这篇关于在这种情况下,我如何联系我的实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 16:35