我有以下关系:
public class Company
{
public int Id { get; set; }
public virtual ICollection<CostCenter> CostCenters { get; set; }
public virtual ICollection<CompanyPassenger> CompanyPassengers { get; set; }
}
public class CompanyPassenger
{
public int Id { get; set; }
public int CostCenterId { get; set; }
public int CompanyId { get; set; }
public virtual CostCenter CostCenter { get; set; }
}
public class CostCenter
{
public int Id { get; set; }
public int CompanyId { get; set; }
}
我需要创建一个拥有新乘客的新公司,并为此乘客提供新的成本中心。我正在做这样的事情:
{
"id": 0,
"CompanyPassenger": [{
"id": 0,
"CompanyId": 0,
"CostCenterId ": 0,
"CostCenter": {
"id": 0,
"CompanyId": 0
}
}]
}
但是当我保存实体时,CostCenter
对象没有保存CompanyId
属性。
有什么建议吗?谢谢乔尼