2

我正在使用ValueInjecter将数据从我的视图模型注入到我的实体框架模型中,对于字符串等非 Id,它的效果很好。出于某种原因,它没有从我的视图中映射选择列表中的 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();
        }
    }
4

1 回答 1

3

这是因为它们的类型不同Guid,而且Nullable<Guid>

于 2011-11-17T12:19:28.657 回答