简体   繁体   中英

“$id” “$type” missed after EFPersistenceManager.saveChanges

I use breeze and aspnetcore in a aulrelia project. when I create new record(A) and save it to database, all work fine, but when I continue to create record(B) to save, the controller still received record A from front-end, then I debugged and compared with another aspnet project which used breeze also. It shows me that key wrods exit, and I guess it should affect the front-end breeze to determine whether record A is saved, maybe that's the reason why when I try to save record B, controller still get record A.

My controller:

[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);
    }

Unit of work:

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);
    }

we need use JsonSerializationFns which from breeze to serialize the result, it will add the key words.

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
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM