0
votes

The code below returns a single record from my database, as-expected. However, it fails to track changes in the UI. I'm binding myObject's properties to various fields using angularjs. Everything initially loads fine, but if I make changes to the object and use breeze's EntityManager.saveChanges(), it doesn't detect than anything has changed. I can create a new entity and save it just fine, but trying to understand how to handle updates. Do I need to detach the entity after I retrieve it, then reattach and save?

Or is this the wrong way to assign a retrieved entity to my javascript (using TypeScript) object? myObject = data.results[0];

let query = breeze.EntityQuery.from("myTable").where('id', '==', incomingId).expand(['relatedTable']);

            dataService.executeQuery(query).then((data) => {
                this.myObject = data.results[0];
            });
1

1 Answers

0
votes

I had to add '.toType("myType")' clause onto the query. I used 'metadataStore.registerEntityTypeCtor' to register my types in the EntityManager, but this step was still necessary for me, which I don't entirely understand.

let query = breeze.EntityQuery.from("myTable").where('id', '==', incomingId).expand(['relatedTable']).toType("myType");

        dataService.executeQuery(query).then((data) => {
            this.myObject = data.results[0];
        });

Edit: I also found that using the EFContextProvider to do my querying improved my results and lessened issues incredibly. In the past, I had only used the Context, and while it worked, my entity types were not understood as well by Breeze on the client side.

readonly EFContextProvider<Context> _contextProvider = new EFContextProvider<Context>();

    [HttpGet]
    public IQueryable<Dispute> Disputes()
    {
        return _contextProvider.Context.Disputes;
    }