wesley Wang
wesley Wang

Reputation: 103

Breeze server side saving changes without Entity Framework

I am using breeze without Entity Framework, is there a way to save the whole change set in one go on the server side? Or do I have to loop through the list of entities and save each individual one based on the checking of the entity state? Thanks in advance!!!

Upvotes: 0

Views: 298

Answers (2)

Jay Traband
Jay Traband

Reputation: 17052

You can certainly save the whole change set in a single EntityManager.saveChanges call. Take a look at the NoDb sample in the breeze.js.samples GitHub repo and you will see an example of this.

You will, of course, need to implement that actual save operation yourself on the server, but the server will receive the entire change set for you to work with.

In addition, if you don't want to use EF, there are several other breeze backend server technologies that you can use instead. Take a look at the breeze GitHub repos for .NET, Node, and Java versions of the .NET server.

  • breeze.server.net
  • breeze.server.node
  • breeze.server.java

These include server implementations for the following combinations

  • .NET/Entity Framework ( any SQL db that EF supports)
  • .NET/Hibernate - ( any SQL db that NHibernate supports)
  • Node/Sequelize - ( MySql/Postgress databases)
  • Node/Mongo - ( Mongo db databases)
  • Java/Hibernate - ( any SQL db that Hibernate supports)

Upvotes: 0

Risky Pathak
Risky Pathak

Reputation: 616

I had similar scenario with NancyFx (Without EF - OrmLite as ORM), Breeze and AngularJs. I googled a lot but did not find any good resources which can help me. After a lot of hit and trial coding, I wrote the code to accomplish.

Below are the brief steps.

  1. Use EF only to generate metadata. You can remove EF in production.

  2. Save EF Metadata into a metadata.js which will be used by client to load metadata.

  3. Make changes in your application to pick metadata from js file and not from server.

  4. Define your own SaveChanges method at server.

    private dynamic SaveChanges(dynamic arg)
    {
        var requestBody = this.Request.Body;
        int length = (int)requestBody.Length; //this is a dynamic variable.
        byte[] data = new byte[length];
        requestBody.Read(data, 0, length);
    
        JObject saveBundle = JObject.Parse(System.Text.Encoding.Default.GetString(data));
    
        for (int i = 0; i < saveBundle["entities"].Count(); i++)
        {
            JToken entity = saveBundle["entities"][i];
    
            switch ((string)entity["entityAspect"]["entityTypeName"])
            {
                case "Node:#Breeze":
                    Node node = NodeContext.Process(entity);
                    break;
            }
        }
    
        return this.Request.Body;
    }
    

"Node:#Breeze" should be replaced by "EntityName:NameSpace" NodeContext should be replaced by some user defined class where we will be processing entity(CRUD operations) on base of entity state.

Upvotes: 0

Related Questions