Question I'm trying something new here with a program I made earlier. In the first program I was able to drag and drop table adapters and use the generic "var" to store query results. Now I'm trying to create a new program that has some separation of code. For example in the first program I had all of the code written in the form.cs file, this time I'd like to create a class to run the queries and return them to the calling class, however, how do you store a query result that contains many types? You cant return a var variable, it must be more specific. I get an error on the select line that reads: "Cannot implicitly convert type'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.IEnumerable;. An explicit conversion exists(are you missing a cast?)
Can some one help me? What is the cast? The first method (public IEnumerable getList()) works as expected its the second method, (public IEnumerable getRecipeInfo(string recipeName)) where I get the error. Here's my code so far.
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;
}
}
}
Thanks in advance for any help!!