EFPersistenceManager.saveChanges 后遗漏了“$id”“$type”

"$id" "$type" missed after EFPersistenceManager.saveChanges

我在aulrelia 项目中使用breeze 和aspnetcore。当我创建新记录(A)并将其保存到数据库时,一切正常,但是当我继续创建记录(B)进行保存时,控制器仍然从前端接收到记录 A,然后 我调试并与另一个也使用 breeze 的 aspnet 项目进行了比较。它告诉我key wrods退出了,我想这应该会影响前端判断记录A是否被保存,也许这就是为什么当我尝试保存记录B时,控制器仍然得到记录A的原因。

我的控制器:

[Produces("application/json")]
[Route("breeze/[controller]/[action]")]
[BreezeQueryFilter]

public class JumpstartController : Controller
{
    private readonly IUnitOfWork _uitOfWork;

    public JumpstartController(IUnitOfWork uitOfWork)
    {
        _uitOfWork = uitOfWork;
    }

    ......

    [HttpPost]
    [AllowAnonymous]
    public SaveResult SaveChanges([FromBody] JObject saveBundle)
    {
        return _uitOfWork.Commit(saveBundle);
    }

工作单元:

readonly EFPersistenceManager<JumpstartEntities> _persistenceManager =
   new EFPersistenceManager<JumpstartEntities>();

   // private readonly JumpstartContextProvider _contextProvider;
    /// <summary>
    /// ctor
    /// </summary>
    public UnitOfWork()
    {
        TenantRepository = new Repository<Tenant>(_persistenceManager.Context);
    }

    /// <summary>
    /// Reporitories
    /// </summary>
    public IRepository<Tenant> TenantRepository { get; private set; }


    /// <summary>
    /// Get breeze Metadata
    /// </summary>
    /// <returns>String containing Breeze metadata</returns>
    public string Metadata()
    {
        return _persistenceManager.Metadata();
    }

    /// <summary>
    /// Save a changeset using Breeze
    /// </summary>
    /// <param name="changeSet"></param>
    /// <returns></returns>
    public SaveResult Commit(JObject changeSet)
    {
        return _persistenceManager.SaveChanges(changeSet);
    }

我们需要使用来自breeze的JsonSerializationFns来序列化结果,它会添加关键字。

mvcBuilder.AddJsonOptions(opt => {
    var ss = JsonSerializationFns.UpdateWithDefaults(opt.SerializerSettings);
    var resolver = ss.ContractResolver;
    if (resolver != null) {
      var res = resolver as DefaultContractResolver;
      res.NamingStrategy = null;  // <<!-- this removes the camelcasing
    }