我已经从我的数据库中生成了我的模型。其中一个模型的样子:MVC实体框架无法找到密钥
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点快速与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
。它也是身份。如果我检查图表,就是这么说的。
从我所看到的,映射是好的。我所有的键,关系,主键,标识字段在图中标识。
你的数据库中的主键是哪一列?你真的有主键吗? – Robert
我编辑了帖子。请检查底部。 – tzortzik
你的编辑不会帮助..你的数据库表中是否有一个主键? – BenjaminPaul