简体   繁体   English

使用Breeze获取数据库中“忽略”的数据

[英]Getting data with Breeze that is “Ignore”d in the database

I am building a SPA and are using BreezeJS for data management. 我正在建立一个SPA,并且正在使用BreezeJS进行数据管理。 Now I want to be able to set processed data on my model class that are not present in the database and send it up the client. 现在,我希望能够在模型类上设置数据库中不存在的已处理数据,并将其发送给客户端。 The problem is that breeze also ignores these properties. 问题在于,微风也忽略了这些属性。

public class MyModel{
     public int Id{get; set;}
     public string Name{get; set;}
     public string ProcessedData{get; set;}
}
...
Ignore(model=> model.ProcessedData);

I realize that Breeze uses the same metadata as my datacontext, but there should be a way to override it. 我意识到Breeze使用与我的数据上下文相同的元数据,但是应该有一种方法可以覆盖它。

The ignored properties is sent by the controller as json, it's just a matter of making breeze parse it as I need it to. 被忽略的属性由控制器以json的形式发送,这只是让微风解析它的问题(根据需要)。

I haven't confirmed this but I think that if your are sure that the data is being returned from the server then you can add "unmapped" properties with the correct names to the Breeze client and it will materialize these as well. 我还没有确认这一点,但是我认为,如果您确定从服务器返回了数据,则可以将具有正确名称的“未映射”属性添加到Breeze客户端,它也会实现。 See the "unmapped" discussion here: http://www.breezejs.com/documentation/extending-entities . 请参阅此处的“未映射”讨论: http : //www.breezejs.com/documentation/extending-entities

Or you could try this ( I haven't actually tested this) AFTER the metadata has already been returned. 或者,您也可以在返回元数据之后尝试这样做(我尚未实际测试过)。

var dp = new breeze.DataProperty( {
    nameOnServer: "ProcessedData", 
    dataType: "String",
    isUnmapped: true
});

myEntityManager.metadataStore.getEntityType("MyModel").addProperty(dp);

and then try your query. 然后尝试查询。

Note: only "unmapped" properties can be added to the EntityType after the EntityType has been itself added to a MetadataStore. 注意:在将EntityType本身添加到MetadataStore之后,只能将“未映射”属性添加到EntityType。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM