Asp.net mvc 从属角色中的所有属性都可以';不能是非空的

Asp.net mvc 从属角色中的所有属性都可以';不能是非空的,asp.net-mvc,entity-framework,Asp.net Mvc,Entity Framework,我有这个联系方式 namespace School.Models { public partial class ContactInfo { public ContactInfo() { this.Branches = new List<Branch>(); this.People = new List<Person>(); } public long ID { get; set; } [Requi

我有这个联系方式

namespace School.Models
{
public partial class ContactInfo
{
    public ContactInfo()
    {
        this.Branches = new List<Branch>();
        this.People = new List<Person>();
    }

    public long ID { get; set; }

    [Required]
    [DataType( System.ComponentModel.DataAnnotations.DataType.PhoneNumber)]
    [StringLength(12, MinimumLength=9)]
    public string PhoneNumber { get; set; }
    [Required]
    [DataType(System.ComponentModel.DataAnnotations.DataType.PhoneNumber)]
    public string CellNumber { get; set; }

    [Required(ErrorMessage="Please enter a valid email like name@domain.com")]
    [DataType(System.ComponentModel.DataAnnotations.DataType.EmailAddress, ErrorMessage="xyz@domain.com")]
    public string Email { get; set; }

    public virtual ICollection<Branch> Branches { get; set; }
    public virtual ICollection<Person> People { get; set; }
}
}
namespace-School.Models
{
公共部分类联系人信息
{
公共联系人信息()
{
this.branchs=新列表();
this.People=newlist();
}
公共长ID{get;set;}
[必需]
[数据类型(System.ComponentModel.DataAnnotations.DataType.PhoneNumber)]
[StringLength(12,最小长度=9)]
公共字符串PhoneNumber{get;set;}
[必需]
[数据类型(System.ComponentModel.DataAnnotations.DataType.PhoneNumber)]
公共字符串CellNumber{get;set;}
[必需(ErrorMessage=“请输入有效的电子邮件,如name@domain.com")]
[数据类型(System.ComponentModel.DataAnnotations.DataType.EmailAddress,ErrorMessage=”xyz@domain.com")]
公共字符串电子邮件{get;set;}
公共虚拟ICollection分支{get;set;}
公共虚拟ICollection人员{get;set;}
}
}
我必须设置所有这些必填字段,但当我设置这些字段时,会出现一个错误,我无法这样做。如果我删除了任何一个必需的标记,但当我将所有标记都设置为必需时开始给出错误,那么它就起作用了。 是否有任何方法可以设置所有这些字段“电话号码”、“手机号码”、“电子邮件”必填项。
提前谢谢

确切的错误是什么?您什么时候得到它(如:code)?@GertArnold它编译得很好,没有问题,但当我转到url,即controller/create时,我得到“依赖角色中的所有属性都可以为Null”请显示相关的映射。这听起来像是人为的外键问题。哪一个?联系人或联系方式@格塔诺尔