有没有人会听我说,并帮助我解决我的问题?
我有3个班级(产品,批次和物料):
每个产品都有很多批次,每个批次都有很多物料。
public class Product {
public int id { get; set; }
public string name { get; set; }
}
public class Lot {
public int id { get; set; }
public decimal price { get; set; }
}
public class Rem {
public int id { get; set; }
public string note { get; set; }
}
答案 0 :(得分:0)
根据您上面的描述,这是EF中相关实体的一种简单方法。
public class Product {
public int id { get; set; }
public string name { get; set; }
public Lot LotId {get; set; }
public ICollection<Lot> Lots { get; set; }
}
public class Lot {
public int id { get; set; }
public decimal price { get; set; }
public Product ProductId {get; set; }
public Product Product {get; set; }
public Rem RemId {get; set; }
public ICollection<Rem> Rems { get; set; }
}
public class Rem {
public int id { get; set; }
public string note { get; set; }
public Lot LotId {get; set; }
public Lot Lot { get; set; }
}
和dbcontext类
public class AppDbContext: DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options): base(options)
{
}
public DbSet<Product> Products { get; set; }
public DbSet<Lot> Lots { get; set; }
public DbSet<Rem> Rems { get; set; }
}
中找到有关EF中关系的进一步说明。