对于Int32,ASP MVC4值太大或太小 - 但对于字符串?

时间:2013-12-17 11:00:45

标签: asp.net asp.net-mvc-4

这对于经验丰富的MVC(4)人来说可能是显而易见的,所以请提前道歉。

我收到错误“对于Int32,值太大或太小。”

Class LEARNER具有Key LearnRefNumber,它被定义为Class中的String。 在我的模型中,它一致地定义为字符串(CSDL)和varchar2(SSDL);这两者的XML片段都在本文的底部。

当我传递一个字符串时,该属性被定义为一个字符串。我有点不知道为什么我会收到这个错误。这是MVC反思的结果吗?有人可以提出解决方法吗?

错误似乎发生在DbSet的Find方法中。

    // My Controller ActionResult Code

    public ActionResult Details(string id)
    {
        LEARNER learner = db.LEARNERS.Find(id);
        // The above line generates an exception when I pass in the string 20044010
        // as id.

        if (learner == null)
        {
            return HttpNotFound();
        }
        return View(learner);
    }

来自CSDL和SSDL的XML片段分别如下:

    <EntityType Name="LEARNER">
      <Key>
        <!--<PropertyRef Name="UKPRN" />-->
        <PropertyRef Name="LearnRefNumber" />
      </Key>
      <Property Type="String" Name="LearnRefNumber" Nullable="false" Unicode="false" FixedLength="false" MaxLength="12" />
      <Property Type="Int32" Name="ULN" Nullable="false" />
      <Property Type="String" Name="FamilyName" Nullable="false" Unicode="false" />
      <Property Type="String" Name="GivenNames" Nullable="false" Unicode="false" />
      <Property Type="DateTime" Name="DateOfBirth" Nullable="false" />
    </EntityType>

    <EntityType Name="LEARNER">
      <Key>
        <!--<PropertyRef Name="UKPRN" />-->
        <PropertyRef Name="LearnRefNumber" />
      </Key>
      <Property Name="LearnRefNumber" Nullable="false" Type="varchar2" MaxLength="12" />
      <Property Name="ULN" Type="number" Precision="10" />
      <Property Name="FamilyName" Type="varchar2" MaxLength="100" />
      <Property Name="GivenNames" Type="varchar2" MaxLength="100" />
      <Property Name="DateOfBirth" Type="date" />
     </EntityType>

LEARNER课程定义

   public partial class LEARNER
   {
    public LEARNER()
    {
        this.LEARNERCONTACTPREFERENCES = new HashSet<LEARNERCONTACTPREFERENCES>();
        this.LEARNERCONTACTs = new HashSet<LEARNERCONTACT>();
        this.LEARNERFAMs = new HashSet<LEARNERFAM>();
        this.LLDDANDHEALTHPROBS = new HashSet<LLDDANDHEALTHPROBS>();
        this.LEARNERPROVIDERSPECMONs = new HashSet<LEARNERPROVIDERSPECMON>();
        this.LEARNEREMPLOYMENTSTATUS = new HashSet<LEARNEREMPLOYMENTSTATUS>();
        this.LEARNINGDELIVERies = new HashSet<LEARNINGDELIVERY>();
    }

    public String LearnRefNumber { get; set; }
    public int ULN { get; set; }
    public string FamilyName { get; set; }
    public string GivenNames { get; set; }
    public System.DateTime DateOfBirth { get; set; }
    public short Ethnicity { get; set; }
    public string Sex { get; set; }
    public short LLDDHealthProb { get; set; }
    public string NINumber { get; set; }
    public short PriorAttain { get; set; }
    public short Accom { get; set; }
    public int ALSCost { get; set; }
    public short Dest { get; set; }
    public int UKPRN { get; set; }
    public int REC_ID { get; set; }
    public string PrevLearnRefNumber { get; set; }
    public int PrevUKPRN { get; set; }
    public short PlanLearnHours { get; set; }
    public short PlanEEPHours { get; set; }

    public virtual ICollection<LEARNERCONTACTPREFERENCES> LEARNERCONTACTPREFERENCES { get; set; }
    public virtual ICollection<LEARNERCONTACT> LEARNERCONTACTs { get; set; }
    public virtual ICollection<LEARNERFAM> LEARNERFAMs { get; set; }
    public virtual ICollection<LLDDANDHEALTHPROBS> LLDDANDHEALTHPROBS { get; set; }
    public virtual ICollection<LEARNERPROVIDERSPECMON> LEARNERPROVIDERSPECMONs { get; set; }
    public virtual ICollection<LEARNEREMPLOYMENTSTATUS> LEARNEREMPLOYMENTSTATUS { get; set; }
    public virtual ICollection<LEARNINGDELIVERY> LEARNINGDELIVERies { get; set; }
}

1 个答案:

答案 0 :(得分:0)

答案结果(部分)是ULN属性的数据类型(从Int32修改为Int64)。

根据建议对此进行了更正,现在的工作方式正如我所希望的那样。得到教训。再次感谢您的帮助。

此致

利。