小编Eza*_*zak的帖子

使用实体框架通过 ID 从其他表中获取值

我有两个已经存在的表(没有外键):

客户 (Id, Name, .....) 项目 (Id, CustomerId, name)

在我的 asp.net 核心应用程序中,我有两个模型:

public class Customer {
   public int Id { get; set; };
   public String Name { get; set; };
}

public class Project {
   public int Id { get; set; };
   public Customer Customer{ get; set; };
   public String Name{ get; set; };
}
Run Code Online (Sandbox Code Playgroud)

以及用于此的数据上下文类

public class CustomerContext: DbContext
{
    public CustomerContext(DbContextOptions<CustomerContext> options) : base(options)
    {
    }

    public DbSet<CustomerContext> Customer { get; set; }
}

public class ProjectContext: DbContext …
Run Code Online (Sandbox Code Playgroud)

fluent entity-framework-core asp.net-core

3
推荐指数
1
解决办法
8927
查看次数