Nullable <system.datetime>和BreezeJS </system.datetime>

时间:2013-04-26 11:10:48

标签: breeze

我有这堂课:

公共部分类VehicleSize     {         public VehicleSize()         {         }

    public System.Guid VehicleSizeId { get; set; }
    public int Title { get; set; }
    public int SizeOrder { get; set; }
    public System.DateTime DateCreated { get; set; }
    public Nullable<System.DateTime> DateDeleted { get; set; }

}

我正在使用BreezeJS。

Nullable的处理似乎有点奇怪。该字段是可选的。但它直到我从javascript明确设置DateDeleted = null时才会抱怨。如果我没有将该字段设置为null,我将得到“问题保存TypeError:entity.dateDeleted为null”。

似乎我在javascript中检查.dateDeleted属性它是一个javascript Date对象但是getTime isNAN。在这种情况下,它不应该为null,而BreezeJS验证器会跳过验证它,因为该字段为空。

来自服务器的元数据将字段定义为:

“name”:“DateDeleted”, “type”:“Edm.DateTime”, “可以”:“真实”

有没有人知道如何创建可选的DateTime字段?


继续我原来的帖子。问题似乎与将实体从一个实体经理出口到另一个实体经理有关。在此代码所示的情况下,再次导入后,以“null”开头的Date字段变为“Invalid Date”:

        var vehicleSizeId = 'E9DA5803-BB65-4751-AA22-17B54A1EE7C1';
        alert('getting vehicle from db');

        var query = breeze.EntityQuery
            .from("VehicleSizes")
            .where("vehicleSizeId", "==", vehicleSizeId);

        var em = new breeze.EntityManager("api/Todo");
        em.enableSaveQueuing(true);

        var sandBoxEm = em.createEmptyCopy();
        sandBoxEm.enableSaveQueuing(true);

        em.executeQuery(query)
           .then(function (data) {
               alert('Found the vehicle size in the original entity manager')
               var entity = data.results[0];
               alert('Org Date Deleted == ' + entity.dateDeleted); // Its null at this point


               var bundle = em.exportEntities();
               sandBoxEm.importEntities(bundle, { mergeStrategy: breeze.MergeStrategy.OverwriteChanges });


           });


        sandBoxEm.executeQuery(query)
            .then(function (data) {
                alert('Found the vehicle size')
                var entity = data.results[0];
                alert('Date Deleted == ' + entity.dateDeleted); // Now its invalid date
                entity.sizeOrder = entity.sizeOrder + 1;
                entity.titleTranslation.text = entity.titleTranslation.text + "_x";
                //entity.titleTranslation.dateDeleted = null;
                //entity.dateDeleted = null;
                try {
                    sandBoxEm.saveChanges().then(
                        function () {
                            alert('It saved ok');
                        }).fail(
                            function (error) {
                                var firstItem = error.entitiesWithErrors[0];
                                var firstError = firstItem.entityAspect.getValidationErrors()[0];
                                var msg = "prop: " + firstError.property.parentType.name + " = " + firstError.errorMessage;
                                alert(msg);
                            }
                        );
                }
                catch (ex) {
                    alert( "Problem saving " + ex );
                }
            }

            ).fail(

            function () {
                alert('Getting the vehicle size failed');
            });

1 个答案:

答案 0 :(得分:1)

修改:2013年5月8日 - 导入先前导出的空日期的问题现已在v 1.3.3中修复,并在Breeze网站上提供。


不确定您遇到了什么。我刚刚编写了一个单元测试来尝试确认你所看到的内容并且无法重现你的问题。我正在针对Employee模型运行此操作,其中“birthDate”也定义为Nullable。

所有测试都传递了这个:

 var em = newEm();  // creates a new EntityManager
 var emp = em.createEntity("Employee", { firstName: "Joe", lastName: "Smith" });
 ok(emp.entityAspect.entityState === breeze.EntityState.Added, "entityState should be 'Added'");
 var birthDate = emp.getProperty("birthDate");
 ok(birthDate === null, "birthDate should be null");
 var q = EntityQuery.from("Employees").where("birthDate", "==", null);

 stop();
 em.executeQuery(q).then(function(data) {
    var empsWithNullBirthDates = data.results;
    ok(empsWithNullBirthDates.length > 0, "should be at least 1 employee with a null birthdate");
    empsWithNullBirthDates.forEach(function(emp) {
       var birthDate = emp.getProperty("birthDate");
       ok(birthDate === null, "queried birthDate should be null");
    });
 }).fail(testFns.handleFail).fin(start);