2
我使用ValueInjecter將數據從我的視圖模型注入到我的實體框架模型中,對於非Ids如字符串它非常好。出於某種原因,它並未映射我視圖中選擇列表的ID,一旦映射它們顯示爲空。任何想法爲什麼?ValueInjector沒有映射來自視圖模型的ID
[HttpPost]
public ActionResult Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
//inject the view model into db model
Core.Models.User user = new User();
user.InjectFrom(model);
視圖模型
[Required(ErrorMessage = "Organization is required")]
[DisplayName("Organization")]
public Guid OrganizationId
{ get; set; }
實體框架模型屬性
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Guid> OrganizationId
{
get
{
return _OrganizationId;
}
set
{
OnOrganizationIdChanging(value);
ReportPropertyChanging("OrganizationId");
_OrganizationId = StructuralObject.SetValidValue(value);
ReportPropertyChanged("OrganizationId");
OnOrganizationIdChanged();
}
}
查克·諾里斯化險爲夷的!不敢相信我沒有看到。 – NullReference
我假設它是按照這種方式設計的,但是ViewModel不能爲空,而它的通用域模型是這樣的。 – roadsunknown