问题 我正在用我之前制作的程序在这里尝试一些新的东西。在第一个程序中,我能够拖放表适配器并使用通用“var”来存储查询结果。现在我正在尝试创建一个具有一些代码分离的新程序。例如,在第一个程序中,我将所有代码都写在 form.cs 文件中,这次我想创建一个类来运行查询并将它们返回给调用类,但是,如何存储查询结果包含多种类型?您不能返回 var 变量,它必须更具体。我在选择行上收到错误消息:“无法将类型'System.Collections.Generic.IEnumerable' 隐式转换为'System.Collections.Generic.IEnumerable;。存在显式转换(您是否缺少演员表?)
有人能帮我吗?演员阵容是什么?第一种方法 (public IEnumerable getList()) 按预期工作,它的第二种方法 (public IEnumerable getRecipeInfo(string recipeName)) 出现错误。到目前为止,这是我的代码。
namespace recipeDataBase
{
class Query
{
recipiesNewDataSet recipeDataSet = new recipiesNewDataSet();
recipiesNewDataSetTableAdapters.RecipeTableAdapter recipeTableAdapter = new recipiesNewDataSetTableAdapters.RecipeTableAdapter();
recipiesNewDataSetTableAdapters.RecipeIngredientTableAdapter ingredientTableAdapter = new recipiesNewDataSetTableAdapters.RecipeIngredientTableAdapter();
recipiesNewDataSetTableAdapters.RatingTableAdapter ratingTableAdapter = new recipiesNewDataSetTableAdapters.RatingTableAdapter();
public Query()
{
}
public IEnumerable<string> getList()
{
recipeTableAdapter.Fill(recipeDataSet.Recipe);
IEnumerable<string> recipeList = (from a in recipeDataSet.Recipe
select a.RecipeName);
return recipeList;
}
public IEnumerable<string> getRecipeInfo(string recipeName)
{
recipeTableAdapter.Fill(recipeDataSet.Recipe);
ratingTableAdapter.Fill(recipeDataSet.Rating);
ingredientTableAdapter.Fill(recipeDataSet.RecipeIngredient);
IEnumerable<string> recipeInfo = (from a in recipeDataSet.Recipe
from b in recipeDataSet.Rating
from c in recipeDataSet.RecipeIngredient
where a.RecipeName == recipeName &&
a.RecipeNum == c.RecipeNum &&
a.RatingNum == b.RatingNum
select new { a.RecipeName, a.Nationality, a.Event, a.Source, b.FamilyRating, c.Ingredient });
return recipeInfo;
}
}
}
提前感谢您的帮助!!