在使用EF代码时,我会在不同时间收到以下错误:
实体类型SomeType不是当前上下文的模型的一部分.
导致此错误的可能原因是什么?
DB有一张桌子PackagingInfo.我有一Package节课,还有一节课ShopEntities : DbContext.
// Entity (ex. Package.cs)
[Table("PackagingInfo")]
public class Package
{
public decimal PackageID { get; set; }
public decimal Title { get; set; }
public decimal Cost { get; set; }
public bool isFree { get; set; }
}
// Entity Context (ex. ShopEntities.cs)
public class ShopEntities : DbContext
{
public DbSet<Package> Packages { get; set; }
}
// Controller Action (ex. HomeController.cs)
public ActionResult Index()
{
ShopEntities _db = new ShopEntities(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的存储库更新为EF5,但遇到了一些错误.我已经看了一下stackoverflow,因为类似的错误发现了一些问题/答案,但不幸的是,相同的答案并没有解决我的问题.
这是我的错误:
The entity type User is not part of the model for the current context.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Run Code Online (Sandbox Code Playgroud)
这是我的DbContext类:
public abstract class WebModelContext : DbContext
{
public WebModelContext()
: base("WebConnection")
{
Configuration.LazyLoadingEnabled = true;
}
}
Run Code Online (Sandbox Code Playgroud)
这是继承我的WebModelContext类的上下文类:
public class AccountContext : WebModelContext
{
private DbSet<User> _users;
public AccountContext()
: …Run Code Online (Sandbox Code Playgroud)