首先使用EF核心代码在两个表之间进行映射

问题描述 投票:0回答:1

我正在尝试使用如下所示的EF Core code first在以下两个模型之间建立模式和关系

public class Status
{
    public int Id { get; set; }
    public string Status { get; set; }
}

public class Order
{
    public Guid Id  { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public Status status { get; set; }
}

任何人都可以建议是否需要对上述模型(状态和顺序)进行任何更改以获取如下所示的查询结果

     OrderID    description    status
       1            test1      approved
       2            test2      rejected
c# entity-framework entity-framework-core ef-code-first ef-core-3.0
1个回答
0
投票

将导航属性“状态”设置为虚拟属性,例如:

{
    public int Id { get; set; }
    public string Status { get; set; }
}

public class Order
{
    public Guid Id  { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public virtual Status status { get; set; }
}    ```

Then you can do ```  Order.Status.Status  ``` for each row while displaying
© www.soinside.com 2019 - 2024. All rights reserved.