我正在使用ValueInjecter将我的视图模型中的数据注入到我的实体框架模型中,而对于诸如字符串之类的非ID,它可以很好地工作。由于某种原因,它不会在我的视图中映射选择列表中的ID,一旦映射它们显示为null。有什么想法吗?
[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();
}
}
答案 0 :(得分:3)
这是因为它们的类型不同Guid
和Nullable<Guid>