Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 readingqueryingfiltering 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
131 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...