【发布时间】:2012-02-28 22:05:17
【问题描述】:
我正在尝试使用以下代码将实体添加到我的数据库中:
public void StoreElectronicSignatureType(ElectronicSignatureTypeModel model)
{
[...]
ElectronicSignatureType electronicSignatureType = new ElectronicSignatureType();
Entity entity = GetEntity("Test");
electronicSignatureType.Entity = entity;
Add(electronicSignatureType);
public void Add(object entity)
{
DbContext.Entry(entity).State = System.Data.EntityState.Added;
//DbContext.Set(entity.GetType()).Add (entity);
DbContext.SaveChanges();
}
当我这样做时,我收到以下错误:
{"Invalid column name 'Custom.MonsterBehandeling'."}
我能找到的这个错误的例子都是关于尝试从他们尝试选择的列不存在的数据库中选择数据,所以我认为我正在尝试插入列Custom.MonsterBehandeling没有该列。事实上,在数据库中查看“Test”表并没有 Custom.MonsterBehandeling。
但是,实体Test 不包含Custom、MonsterBehandeling 或Custom.MonsterBehandeling。在整个解决方案中搜索MonsterBehandeling 只会得到两次点击:
<CustomTable Name="Sample">
<Columns>
<ColumnDefinition IsUnique="false" IsDiscriminator="false" IsIdentity="false" Description="Monster behandeling" Size="0" Precision="0" Scale="0" DataType="Text" Name="MonsterBehandeling" IsPrimaryKey="false" AllowNull="true" />
</Columns>
</CustomTable> <field name="ItemExpression" value="Sample.Custom.MonsterBehandeling"/>
在我没有使用的数据库架构中,删除它仍然会出现相同的错误,并且
<field name="ItemExpression" value="Sample.Custom.MonsterBehandeling"/>
在 configuration.xml 文件中。同样在删除它之后,我仍然得到同样的错误。
看到我什至在数据库或我的解决方案中都找不到MonsterBehandeling,我不知道从哪里开始寻找解决方案。另外,我不确定为什么我认为我得到这个错误是正确的。那么,插入数据时出现{"Invalid column name '...'."}错误的原因是什么,我该如何解决呢?
【问题讨论】:
-
您使用的是模型优先、数据库优先还是代码优先?
-
我首先使用数据库
标签: c# entity-framework insert add dbcontext