标签: csdl

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

标签 统计

c# ×1

csdl ×1

dbcontext ×1

ef-model-first ×1

entity-framework ×1