Question

Here is the code:

breeze.config.initializeAdapterInstance('dataService', 'odata', true);
var manager = new breeze.EntityManager('...');
manager.fetchMetadata().then(function() {
   var item = manager.createEntity('Todo', { Description: "Have fun",  CreatedAt: new Date(), IsDone: false});
   manager.saveChanges().then(function(data) {
      console.log('save ok:', data);
   }).fail(function(err) {
      console.log('save failed:', err);
   });
});

This code sends to server following record:

{"Id":"K_-1","Description":"Have fun","CreatedAt":"2014-06-03T18:16:11.982","IsDone":false}

I guess that could happen because my oData provider returns metadata not suitable for breeze:

<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
    <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0" m:MaxDataServiceVersion="2.0">
        <Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="TodoDatabase">
            <EntityType Name="Todo">
                <Key>
                    <PropertyRef Name="Id"/>
                </Key>
                <Property xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation" Name="Id" p6:StoreGeneratedPattern="Identity" Type="Edm.String"/>
                <Property MaxLength="200" Name="Description" Nullable="false" Type="Edm.String"/>
                <Property Name="CreatedAt" Type="Edm.DateTime"/>
                <Property Name="IsDone" Type="Edm.Boolean"/>
            </EntityType>
            <EntityContainer m:IsDefaultEntityContainer="true" Name="Service">
                <EntitySet EntityType="TodoDatabase.Todo" Name="Todos"/>
            </EntityContainer>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>
Was it helpful?

Solution

Breeze generates temporary IDs for store-generated keys ... which is what your metadata says you have. Your OData provider should have no problem receiving a temporary ID value such as -1. It should replace that with the permanent ID value and Breeze will make the adjustment on the client when it receives the inserted record.

Why are you concerned about the temp key value? Is the server objecting? If so how?

I cannot explain the "K_" prefix in {"Id":"K_-1","Description": ...; perhaps you can.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top