对角/微风SPA模板映射的财产 [英] UnMapped property on the Angular/Breeze SPA template

查看:134
本文介绍了对角/微风SPA模板映射的财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的Visual Studio 2012的角/微风SPA模板,我已经加入了TodoList的服务器模型未映射属性。

I am using the Angular/Breeze SPA template in visual studio 2012. I have added an unmapped property in the TodoList server model.

[NotMapped]
public string MyUnmappedProperty{ get{return "testString";}} 

我已经注册在客户端模型构造函数中未映射的财产,特别是在像todo.model.js沃德这里建议:<一href=\"http://stackoverflow.com/questions/16524073/handling-calculated-properties-with-breezejs-and-web-api/18011157#18011157\">Handling与breezejs和Web API 计算特性。

function TodoList() {
        this.title = "My todos"; // defaults
        this.userId = "to be replaced";
         this.myUnmappedProperty="";
    }

当getTodos()方法被调用的todo.controller.js的第一次,myUnmappedProperty已经在构造函数中设置为空字符串值。 getTodos()被称为第二次后才(我已经添加了一个按钮,这是否)与forceRefresh设置为true(getTodos(真)),以查询服务器,只有我看到了myUnmappedProperty获取值的TestString。

When the getTodos() method is called on the todo.controller.js for the first time, the "myUnmappedProperty" has the value of the empty string as set in the constructor. Only after getTodos() is called for the second time( I have added a button that does that) with 'forceRefresh' set to true (getTodos(true)) in order to query the server, only then I see the myUnmappedProperty getting the value "testString".

我想知道为什么我收到这种行为。是否有可能有未映射属性充满了服务器值首次getTodos()被调用?

I am wondering why I am getting this behaviour. Is it possible to have the unmapped property filled with the server value the first time the getTodos() is called?

感谢您。

推荐答案

你有没有找到解决这个问题呢?我一直在挣扎了同样的问题,只是最近发现的this通过CassidyK,其中他在微风源$ C ​​$ C(breeze.debug.js)改变单一线路解决了一个非常类似的问题,所以帖子。这里是code段他改变(从CassidyK的后服用):

Did you find a solution to this problem? I have been struggling with the same problem and just recently found this SO post by CassidyK, in which he solves a very similar problem by changing a single line in the Breeze source code (breeze.debug.js). Here is the code snippet he changed (taken from CassidyK's post):

proto.initializeFrom = function (rawEntity) {
    // HACK:
    // copy unmapped properties from newly created client entity to the rawEntity.
    // This is so that we don't lose them when we update from the rawEntity to the target.
    // Something that will occur immediately after this method completes. 
    var that = this;
    this.entityType.unmappedProperties.forEach(function(prop) {
        var propName = prop.name;
        that[propName] = rawEntity[propName];  // CassidyK 
        //rawEntity[propName] = that[propName]; // Breeze 
    });

    if (!this._backingStore) {
        this._backingStore = { };
    }
};

我曾尝试这种解决方案,它似乎工作得很好。请注意,这种变化将可能让你陷入麻烦,如果你曾经有在你这不是在数据库映射到服务器端性能的情况,需要在客户端在客户端创建对象时覆盖此值。

I have tried this solution and it seems to work just fine. Notice that this change will probably get you into trouble if you ever have a case in which you have a server side property that's not mapped in the database, and need the client side to overwrite this value when the object is created at the client side.

这篇关于对角/微风SPA模板映射的财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆