我有两个已经存在的表(没有外键):
客户 (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)