Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从实体框架数据库获取类中包含的项列表_C#_.net_Asp.net Mvc - Fatal编程技术网

C# 如何从实体框架数据库获取类中包含的项列表

C# 如何从实体框架数据库获取类中包含的项列表,c#,.net,asp.net-mvc,C#,.net,Asp.net Mvc,我的申请有问题。我无法从数据库中获取包含列表的对象。我真的不擅长实体框架,所以很抱歉,如果这是一个非常大的错误 public List<Recipe> GetRecipes(Cook cook) { List<Recipe> L_Recipes = new List<Recipe>(); Cook Cook = dbc.DbCook.SingleOrDefault(c => c.Nickname == cook.N

我的申请有问题。我无法从数据库中获取包含列表的对象。我真的不擅长实体框架,所以很抱歉,如果这是一个非常大的错误

public List<Recipe> GetRecipes(Cook cook)
    {
        List<Recipe> L_Recipes = new List<Recipe>();
        Cook Cook = dbc.DbCook.SingleOrDefault(c => c.Nickname == cook.Nickname);
        L_Recipes = Cook.ListRecipes;
        return L_Recipes;
    }
问题是我收到了配方的信息,但没有收到其中的列表

它在ASP.NET中

包括代码:

        public List<Recipe> GetRecipes(Cook cook)
    {
        List<Recipe> L_Recipes = new List<Recipe>();
        Cook Cook = dbc.DbCook.Include(c => c.ListRecipes).singleOrDefault(c => c.Nickname == cook.Nickname);
        L_Recipes = Cook.ListRecipes;
        return L_Recipes;
    }
public List GetRecipes(库克)
{
列出L_配方=新列表();
Cook-Cook=dbc.DbCook.Include(c=>c.ListRecipes).singleOrDefault(c=>c.昵称==Cook.昵称);
L_Recipes=Cook.ListRecipes;
返回L_配方;
}
Thx到和 所以答案是使用Include并添加一个using 包括:
public List GetRecipes(库克)
{
列出L_配方=新列表();
Cook-Cook=dbc.DbCook.Include(c=>c.ListRecipes).singleOrDefault(c=>c.昵称==Cook.昵称);
L_Recipes=Cook.ListRecipes;
返回L_配方;
}

使用:
使用System.Data.Entity

您需要使用Include。我试过了,收到的结果是:无法将lambda表达式转换为“string”类型,因为它不是委托类型/我不在ASP.NET Core上。您可以使用“Include”选项发布代码吗?好的。但我不在ASP.NET Core上-请不要发布代码的截图-将实际代码(作为文本)发布到消息中并正确格式化(使用
{..}
按钮)
        public List<Recipe> GetRecipes(Cook cook)
    {
        List<Recipe> L_Recipes = new List<Recipe>();
        Cook Cook = dbc.DbCook.Include(c => c.ListRecipes).singleOrDefault(c => c.Nickname == cook.Nickname);
        L_Recipes = Cook.ListRecipes;
        return L_Recipes;
    }