【发布时间】:2014-01-22 13:56:34
【问题描述】:
我已经从我的数据库中生成了我的模型。其中一个模型看起来像:
namespace LV.Models
{
using System;
using System.Collections.Generic;
public partial class Ac
{
public int IdAc { get; set; }
public int IdEmp { get; set; }
public Nullable<System.DateTime> dtd{ get; set; }
public Nullable<int> Sn{ get; set; }
public Nullable<bool> A{ get; set; }
public Nullable<int> IdSi{ get; set; }
public Nullable<bool> Gest{ get; set; }
public Nullable<int> IdResp { get; set; }
public string SigXML { get; set; }
public Nullable<bool> Read { get; set; }
public Nullable<System.DateTime> EndDate{ get; set; }
public string dpd{ get; set; }
public string gda { get; set; }
public string typeaq { get; set; }
public byte[] attch { get; set; }
public string exten { get; set; }
public virtual AC emps { get; set; }
}
}
当我尝试创建一个控制器时,它显示has no key defined。我尝试了其他帖子中的解决方案,其中说我必须使用[Key],它会创建我的控制器,但是当我运行项目时,它会抛出另一个异常,上面写着the following table cannot be created。它说是因为该表已经存在。
我使用 Visual Studio 2013 Express 和 EF 6 <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
主键是idAc。它也是身份。如果我检查图表,就是它所说的。
据我所见,映射很好。我在图中标识的所有键、关系、主键、身份字段。
【问题讨论】:
-
数据库中的主键是哪一列?你真的有主键吗?
-
我编辑了这篇文章。请检查底部。
-
你的编辑没有帮助..你的数据库表真的有主键吗??
-
是的,我的表有一个主键,它也是一个身份。
标签: c# asp.net-mvc entity-framework