質問以前に作成したプログラムを使用して、ここで何か新しいことを試みています。最初のプログラムでは、テーブルアダプターをドラッグアンドドロップし、汎用の「var」を使用してクエリ結果を保存することができました。今、私はコードがいくらか分離された新しいプログラムを作成しようとしています。たとえば、最初のプログラムでは、すべてのコードをform.csファイルに記述しましたが、今回はクエリを実行して呼び出し元のクラスに返すクラスを作成したいと思いますが、クエリをどのように保存しますか多くのタイプを含む結果?var変数を返すことはできません。より具体的にする必要があります。選択行に次のようなエラーが表示されます。「タイプ'System.Collections.Generic.IEnumerable'を'System.Collections.Generic.IEnumerable;に暗黙的に変換できません。明示的な変換が存在します(キャストがありませんか?)
誰かが私を助けることができますか?キャストは何ですか?最初のメソッド(public IEnumerable getList())は期待どおりに機能し、2番目のメソッド(public IEnumerable getRecipeInfo(stringrecipeName))ではエラーが発生します。これが私のこれまでのコードです。
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;
}
}
}
助けてくれてありがとう!