以下是代码:
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);
});
});
此代码在记录后发送到服务器:
{"Id":"K_-1","Description":"Have fun","CreatedAt":"2014-06-03T18:16:11.982","IsDone":false}
我想这可能发生,因为我的oData提供程序返回的元数据不适合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>
答案 0 :(得分:0)
Breeze为商店生成的密钥生成临时ID ...这就是您的元数据所说的内容。您的OData提供程序应该没有问题接收临时ID值,如-1。它应该用永久ID值替换它,Breeze会在收到插入记录时对客户端进行调整。
为什么你关心临时密钥值?服务器是否反对?如果是这样的话?
我无法解释&#34; K _&#34; {"Id":"K_-1","Description": ...
中的前缀;也许你可以。