Breeze Webapi Update Projections

一世执手 提交于 2019-12-13 07:58:55

问题


Continuing on after my initial WebApi Filtering and paging a projection Dilemma

Breeze $filter projections thread

I am now trying to update my backend database with little success.

Giving the Fact that I am:

    public IQueryable<ConsigneDTO> Consignees(string refname)
    {
        IQueryable<ConsigneDTO> q = this.db.Consignes
             .Where(x => x.Refname == refname)
                  .Select(f => new ConsigneDTO {Refname = f.Refname, Consignee = f.Consignee, Address1 = f.Address1, Address2 = f.Address2, Address3 = f.Address3});
        return q;
    }

Whats the easiest way to put this data back from Breeze?

I see my changed data coming back in both overrides

    protected override bool BeforeSaveEntity(EntityInfo entityInfo)
    {
    }

    protected override Dictionary<Type, List<EntityInfo>> BeforeSaveEntities(Dictionary<Type, List<EntityInfo>> saveMap)
    {
    }

But no easy way to push these into the underlying context which is a WCF service stemming from Data.Services.Client.DataServiceContext.

How do I call

  Context.UpdateChanges(EntityInfo);

or

  Context.UpdateChanges(SaveMap);

Especially Considering EntityInfo and SaveMap contains DTO?

Must I completely ignore the SaveChanges() mechanism and do my own CRUD calls? I don't even see any good non-breeze examples on updating projections, which make me feel this is deep rooted.

As explained in prior thread, I can change most things about this project. The only issues I have are the databases are on another server and has columns that cannot be public and my only way at the tables are EF5.

I've chosen to wrap EF thinly using OData-v3 / WCF-Data-Services and access them from my breeze controller on the web server.

So far reading\querying\filtering and paging are all working great on SPA, but with only the R of "C_UD", I'm more then willing to rework this project.

Kind Regards Mike


回答1:


The Breeze EntityManager.saveChanges call is intended to save changes to entities that were previously queried. This process can be automated by Breeze because it has metadata regarding these entity types and is able to construct the appropriate code on the server to persist them. In your case what you are returning from your queries are not 'entities' and unless you can turn them into entities Breeze will not be able to persist them. So you have several approaches that you can try.

The first is to take your DTO's when retrieved on the client and dynamically construct "partial" entities from them that can later be fully resolved if any changes need to be made. See John Papa's Code Camper sample to see an example of this. As a side note, if your DTO actually includes Breeze entities within the projection then even this is not necessary.

Another approach is to bypass Breeze completely when attempting to save these. Simply use the Breeze ajax adapter directly and post your data directly to whatever endpoint you'd like. Obviously, in this case, you will need to write all of the server side code necessary to persist the posted data.



来源:https://stackoverflow.com/questions/18092009/breeze-webapi-update-projections

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