相关疑难解决方法(0)

EF 4.1 Code First错误 - 实体类型SomeType不是当前上下文的模型的一部分

在使用EF代码时,我会在不同时间收到以下错误:

实体类型SomeType不是当前上下文的模型的一部分.

导致此错误的可能原因是什么?

entity-framework code-first entity-framework-4.1

42
推荐指数
3
解决办法
4万
查看次数

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万
查看次数