0
HI當我嘗試將數據保存到表[ir]時出現錯誤[InspectionQCExceptionRuleConfig]實體框架{「指定的參數超出了有效值的範圍。 r n參數名稱:name」}
{「指定參數超出有效 值的範圍\ r \ n參數名:名」}
我不知道爲什麼,我想保存數據。但是,我能夠從模型中檢索數據。我粘貼了代碼,上下文和域模型。如果有人知道他的。請告訴我..
public InspectionQCExceptionRuleConfig SaveInspectionQCRules
(InspectionQCExceptionRuleConfig inspectionruleconfig)
{
if (inspectionruleconfig != null)
{
try
{
using (InspRulesData ctx = new InspRulesData())
{
inspectionruleconfig = ctx.UpdateGraph(inspectionruleconfig, map => map);
//ctx.InspectionQCExceptionRuleConfigs.Add(inspectionruleconfig);
ctx.SaveChanges();
}
}
catch (DbEntityValidationException ex)
{
Logging.LogError(ex);
throw;
}
catch (Exception ex)
{
Logging.LogError(ex);
throw;
}
}
return inspectionruleconfig;
}
這是從實體框架生成的域模型
namespace DomainModel.FSEntity.InspRules
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
using CommonLib;
[System.CodeDom.Compiler.GeneratedCode("EF", "6.1.0")]
[Table("ir.InspectionQCExceptionRuleConfig")]
public partial class InspectionQCExceptionRuleConfig : BaseDomainModel
{
[Key]
[StringLength(50)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string ClientNumber { get; set; }
public bool QCOrdered { get; set; }
public bool DwellingType { get; set; }
public bool VacantToOccupied { get; set; }
public bool VacantToOccupiedWithActivePreservation { get; set; }
}
}
這是用於實體框架來保存數據O表InspectionQCExceptionRuleConfig
上下文 public partial class InspRulesData : CustomDbContext
{
public InspRulesData()
: base("name=PlatformEntityData")
{
this.Configuration.LazyLoadingEnabled = false;
}
public virtual DbSet<InspectionQCExceptionRuleConfig> InspectionQCExceptionRuleConfigs { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<InspectionQCExceptionRuleConfig>()
.Property(e => e.ClientNumber)
.IsVariableLength()
.IsUnicode(false);
}
}
ClientNumber字符串屬性有多長? –
嗨..這現在解決了。我將clientNumber屬性從字符串更改爲int。我可以保存數據。 – svd