2
我最近实现了一个MVC3网站,现在必须包含来自视图的数据。 如下图所示,我把它设置得非常像我将一张桌子,然后我得到了下面的错误。 我不确定如何设置它。 我已经提供了下面的一些课程来帮助我指出正确的方向。模型生成过程中检测到在DBContext中使用视图
一个或多个验证错误: System.Data.Edm.EdmEntityType:的EntityType“AJF_ProfitCentres”不具有确定的键。 定义此EntityType的关键。 System.Data.Edm.EdmEntitySet:的EntityType: EntitySet的ProfitCentres基于类型 AJF_ProfitCentres有没有键
public class NavContext : DbContext
{
public DbSet<Account> Accounts { get; set; }
public DbSet<AJF_ProfitCentres> ProfitCentres { get; set; }
public NavContext()
: base("NavContext")
{
}
}
public class NavRepository : INavRepository
{
private readonly NavContext _context;
public NavRepository(NavContext context)
{
_context = context;
}
public List<AJF_ProfitCentres> GetAllProfitCentres()
{
return _context.ProfitCentres.ToList();
}
}
public class AJF_ProfitCentres
{
public int ProfitCentreId;
[MaxLength(30, ErrorMessage = "ProfitCentre cannot be longer than 30 characters.")]
public string ProfitCentre { get; set; }
[MaxLength(64, ErrorMessage = "AccountId cannot be longer than 64 characters.")]
public string AccountId { get; set; }
}
好的。这里的问题是我先使用代码和sql视图。我想我会重写代码来使用基础表。 – CouncilScribe