我的数据库和C#模型中都有两个表:
public class Address
{
public int Id { get; set; }
public string Name { get; set; }
public string City { get; set; }
}
public class Customer
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
我还有一个表,该表将Address
和Customer
表与列连接起来:
Id
CustomerId
AddressId
如何使用NPoco在表之间实现多对多关系?
答案 0 :(得分:0)
使用此示例:
BindingResult
并在模型创建时进行配置:
public class Address
{
public int Id { get; set; }
public string Name { get; set; }
public string City { get; set; }
public virtual ICollection<CustomerAddress> CustomerAddresses{ get; set; }
}
public class Customer
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual ICollection<CustomerAddress> CustomerAddresses{ get; set; }
}
public class CustomerAddress
{
public int CustomerId{ get; set; }
public int AddressId{ get; set; }
public virtual Address Address{ get; set; }
public virtual Customer Customer{ get; set; }
}