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