相关疑难解决方法(0)

实体类型<classname>不是当前上下文的模型的一部分

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)

entity-framework ef-code-first

28
推荐指数
1
解决办法
1万
查看次数

The entity type <class> is not part of the model for the current context

This is a MODEL first approach. I have already researched this extensiely and have not come up with an answer. I have tried all the suggestions at the following links:

This appears to be the same problem but with no resolution The entity type <classname> is not part of the model for the current context

These are the links I have already researched so please don't answer as duplicate of ---- EF 4.1 Code First error - The entity type …

entity entity-framework entity-framework-4.1 ef-model-first

8
推荐指数
1
解决办法
8752
查看次数

EntitySet System.InvalidOperationException - "实体类型不是当前上下文模型的一部分"

类似的问题

实体类型<classname>不是当前上下文的模型的一部分 - 并且 - EF 4.1 Code First错误 - 实体类型SomeType不是当前上下文的模型的一部分是类似的问题但它们是"代码优先"透视只有更简单的数据模型,并解决连接字符串和映射问题.请仔细看看这个.

症状

// HomeController.cs
public ActionResult Index()
{
    var _db = new MealsContext();

    var m = _db.Meals.ToList();
    var d = _db.Drinks.ToList();

    return View();
}
Run Code Online (Sandbox Code Playgroud)

抛出异常会检索Drinks集合:

The entity type Drink is not part of the model for the current context.
Run Code Online (Sandbox Code Playgroud)

// Meal.cs
public class Meal
{
    public int Id { get; set; }
    public string Stuff { get; set; }
    public virtual ICollection<Meat> Meats { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework csdl dbcontext ef-model-first

6
推荐指数
1
解决办法
3万
查看次数