首页 > 解决方案 > 将复合主键映射为单个值对象(就 DDD 而言)?

问题描述

是否可以在 Entity Framework Core 中将复合主键映射为单个值对象?然后:它在 LINQ 查询中是否正常工作?

我知道在 EF Core 2.2 之前对 VO 的支持不是很好。

public class AssignmentIdentity
{
    // ...
    public EmployeeIdentity EmployeeId { get; protected set }
    public TaskIdentity TaskId { get; protected set; }
}

public class Assignment
{
    // ...
    public AssignmentIdentity Id { get; protected set }
}

public class EmployeeIdentity
{
    // ...
    public String Identifier { get; protected set }
}

public class Employee
{
    // ...
    public EmployeeIdentity Id { get; protected set }
}

public class TaskIdentity
{
    // ...
    public String Identifier { get; protected set }
}

public class Task
{
    // ...
    public TaskIdentity Id { get; protected set }
}

是否可以在 EF 中映射它?请注意,这种映射和 LINQ 查询在 (n)Hibernate 中是可能的。我希望 EF Core 也一样...

标签: entity-frameworknhibernateentity-framework-coreentity-framework-core-2.2

解决方案


推荐阅读