C# 实体框架{quot;指定的参数超出了有效值的范围。\r\n参数名称:name";}
嗨,我尝试将数据保存到表[ir]。[InspectionQCExceptionRuleConfig]时出错 {”指定的参数超出了有效参数的范围 值。\r\n参数名称:名称“} 我不知道为什么,我正在试图保存数据。但是,我能够从模型中检索数据。我粘贴了代码、上下文和域模型。如果有人知道他的名字。请告诉我C# 实体框架{quot;指定的参数超出了有效值的范围。\r\n参数名称:name";},c#,asp.net-mvc,entity-framework-6,C#,Asp.net Mvc,Entity Framework 6,嗨,我尝试将数据保存到表[ir]。[InspectionQCExceptionRuleConfig]时出错 {”指定的参数超出了有效参数的范围 值。\r\n参数名称:名称“} 我不知道为什么,我正在试图保存数据。但是,我能够从模型中检索数据。我粘贴了代码、上下文和域模型。如果有人知道他的名字。请告诉我 public InspectionQCExceptionRuleConfig SaveInspectionQCRules
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; }
}
}
这是实体框架用于将数据保存到表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);
}
}
公共部分类InspRulesData:CustomDbContext
{
公共InspRulesData()
:base(“name=PlatformEntityData”)
{
this.Configuration.LazyLoadingEnabled=false;
}
公共虚拟数据库集检查QCExceptionRuleConfigs{get;set;}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
modelBuilder.Entity()
.Property(e=>e.ClientNumber)
.IsVariableLength()
.IsUnicode(假);
}
}
这也可能是由于域模型中[NotMapped]属性放置错误造成的。ClientNumber字符串属性的长度是多少?您好。。这个问题现在已经解决了。我将clientNumber属性从string更改为int。我能够保存数据。