EF Core 2.2.3 child record is not saved after update from 2.2.1

岁酱吖の 提交于 2019-12-23 03:45:06

问题


I had the below .net Core code working with Microsoft.EntityFrameworkCore.SqlServer 2.2.1.

After I upgrade the dotnet core sdk to 2.2.3 it is not working. Note that the related entity is not mapped with a FK in DB. I have a partial class that has the relation and has the attribute NotMapped to make this work in 2.2.1 . I am not sure what changed and what I need to add to save header and detail record.

var soHeader = new masSoHeader();
var orderToAdd = Mapper.Map(salesOrder.SalesOrderHeader, soHeader);
orderToAdd.InsertDateTime = DateTime.Now;

var newSalesOrder = _context.masSoHeader.Add(orderToAdd);


var newSoSalesOrderDetails =
    Mapper.Map<List<soSalesOrderDetail>>(salesOrder.SalesOrderDetails);

if (newSoSalesOrderDetails != null)
{
    foreach (var soSalesOrderDetail in newSoSalesOrderDetails)
    {
        soSalesOrderDetail.InsertDateTime = DateTime.Now;
        newSalesOrder.Entity.soSalesOrderDetail.Add(soSalesOrderDetail);


    }
}


int numberOfRowsInserted = _context.SaveChanges();

来源:https://stackoverflow.com/questions/55133538/ef-core-2-2-3-child-record-is-not-saved-after-update-from-2-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!