我有一个错误:
One or more validation errors were detected during model generation:
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'DynamicMenu' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'ambt_Dynamic_Menu' is based on type 'DynamicMenu' that has no keys defined.
在助手类中,代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Data.Models;
using Data;
namespace Ambermoda.Web
{
public class MenuHelper
{
public static List<DynamicMenu> GetMenu()
{
DataContext db = new DataContext();
List<DynamicMenu> list = db.ambt_Dynamic_Menu.ToList();
return list;
}
}
}
所以我不知道该如何解决。我检查了所有(在我看来)会产生这个错误的东西,但是有任何结果。
我有类似的帖子,但其中任何一个都不能解决我的问题。
如果有人有什么想法,请写出来:)
谢谢!
更多代码
动态菜单.cs
[Table("abmt_Dynamic_Menu")]
public class DynamicMenu
{
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int dmn_id { get; set; }
public string dmn_code { get; set; }
public string dnm_parent_code { get; set; }
public string dnm_title { get; set; }
public string dnm_title_en { get; set; }
public int dnm_order { get; set; }
}
数据上下文.cs
public class DataContext : DbContext
{
public DataContext() { }
public DbSet<DynamicMenu> ambt_Dynamic_Menu { get; set; }
}
连接字符串:
<add name="DataContext" providerName="System.Data.SqlClient" connectionString="Data Source=Mikasasa-lap\Mikasasa;Database=Ambermoda;Integrated Security=True;Pooling=False;"/>