【发布时间】:2013-03-04 21:11:19
【问题描述】:
我有一个简单的对象模型 公共类许可证 {
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string CreationUserId { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string LastModifiedUserId { get; set; }
public string LicenseName { get; set; }
public LicenseType LicenseType { get; set; }
public State State { get; set; }
public DateTime DateIssued { get; set; }
public int ValidFor { get; set; }
}
public class State
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string CreationUserId { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string LastModifiedUserId { get; set; }
[StringLength(2)]
[Required]
public string Name { get; set; }
[Display(Name = "Long Name")]
[Required, StringLength(25)]
public string LongName { get; set; }
}
public class LicenseType
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string CreationUserId { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string LastModifiedUserId { get; set; }
[StringLength(100), Required]
public string Description { get; set; }
}
我正在使用热毛巾模板微风,杜兰达尔,淘汰赛。 我有一个简单的添加视图模型
var _licenseAdded = false;
var vm = {
states: ko.observableArray(context.states),
licenseTypes: ko.observableArray(context.licenseTypes),
viewAttached: function () {
var self = this;
$('input[name^="date"]').datepicker();
$('#validFor').spinner({
min: 365,
max: 3650,
step: 30
});
log('add Attached', null, true);
},
activate: function () {
var self = this;
self.original = context.manager.createEntity('License', { licenseName: 'Testing321', dateIssued: moment().format('L') }, null);
log('add Activated', null, true);
},
canDeactivate: function () {
if (_licenseAdded === false) {
return app.showMessage('Are you sure you want to leave this page?', 'Navigate', ['Yes', 'No']);
} else {
return true;
}
},
saveChanges: function () {
$.when(context.saveNewLicense()).done(function () {
_licenseAdded = true;
});
router.navigateTo('home');
},
original: undefined
};
return vm;
这是我的 add.html,一切都很好,并且在保存之前运行良好。
当我调用 saveChanges 时,发送到控制器的 saveBundle 没有附加导航属性,允许存储正确的 State 和 LicenseType 我只得到: 保存包 { “实体”:[ { “身份证”:-1, “CreationUserId”:空, “LastModifiedUserId”:空, "LicenseName": "新的测试用", "发布日期": "2013-03-11T04:00:00Z", “有效”:0, “实体方面”:{ "entityTypeName": "许可证:#Volt.Telecom.Licensing.Models", “实体状态”:“添加”, “原始值映射”:{}, “自动生成密钥”:{ "propertyName": "Id", “autoGeneratedKeyType”:“身份” } } } ], “保存选项”:{ “allowConcurrentSaves”:假 } }
不要以为我能得到比这更多的香草。为什么会发生这种情况?当我在客户端上调试时,状态和 licenseType 导航属性都是正确的并且具有正确的值。
【问题讨论】:
标签: breeze