相关疑难解决方法(0)

继承和复合外键 - 基类中键的一部分,派生类中的另一部分

我在为以下示例数据库模式(在SQL Server中)创建实体框架代码优先映射时遇到问题:

具有复合外键的数据库模式

每个表都包含一个TenantId,它是所有(复合)主键和外键(多租户)的一部分.

A Company是a Customer或a Supplier,我尝试通过Table-Per-Type(TPT)继承映射对此进行建模:

public abstract class Company
{
    public int TenantId { get; set; }
    public int CompanyId { get; set; }

    public int AddressId { get; set; }
    public Address Address { get; set; }
}

public class Customer : Company
{
    public string CustomerName { get; set; }

    public int SalesPersonId { get; set; }
    public Person SalesPerson { get; set; }
}

public class Supplier : Company
{ …
Run Code Online (Sandbox Code Playgroud)

.net inheritance entity-framework table-per-type ef-code-first

17
推荐指数
1
解决办法
4191
查看次数