0

I use Breeze in my asp.net application with the Durandal SPA template.

I need to add an entity to the saveMap which already exists in DB.

Let's take this simple example: the page display an invoice and the invoice's lines. The user add a new invoice's line and click the save button. The SaveChanges controller's action is triggered with ONLY the modified invoice's line. Server side, the total is recalculated and the invoice's total must be modified. But this total is located on the invoice entity so we need to add the invoice's entity to the saveMap.

I found a way to proceed to add a new entity to the saveMap here: Breeze BeforeSaveEntities: how to modify savemap

But the suggested solution is used to add a new entity to the saveMap (Added state) which will create a new record on DB. This is not what I need. I need to add a new entity to the saveMap which (Modified state) will be get the data from DB.

I tried like this:

int invoiceId = 1234;
dc.Configuration.ProxyCreationEnabled = false; // don't forget this!
EFContextProvider<BreezeContext> cp = new EFContextProvider<BreezeContext>();
var acc = dc.Invoices.Where(x => x.Id == invoiceId).FirstOrDefault();
ei = cp.CreateEntityInfo(acc, Breeze.WebApi.EntityState.Modified);
invoices = new List<EntityInfo>();
saveMap.Add(typeof(Invoice), invoices);
invoices.Add(ei);

So far so good.

Then I need to add the total property to the OriginalValuesMap (otherwise modification will not be updated):

ei.OriginalValuesMap.Add("TotalExclVAT", invoice.TotalExclVAT);

**This don't work: ei.OriginalValuesMap is null and so I cannot add a new key inside.

I don't know if this is the right way to proceed. Hope my explanations are clear enough.

Thanks for your help.


UPDATE

As suggested by Jay:

ei.ForceUpdate = true; 

No need to take care of OriginalValuesMap in this case.

4

1 に答える 1

2

これについてはまだ掘り下げる機会がありませんが、EntityInfo.ForceUpdate プロパティを見たことがありますか。

このプロパティは、サーバー側の変更が既存のエンティティに対して行われた場合に、エンティティ全体のサーバー側の更新を強制するために使用できます。EntityInfo.OriginalValuesMap を明示的に更新する代わりに使用できます。

これまでのところ、これはリリース ノートに記載されているだけなので、見落とされる可能性があることは理解できます。

于 2013-09-11T18:21:08.443 に答える