I made 2 tables in an SQLite database - Ingredients and Recipes.
A Recipe object uses Ingredient objects, naturally.
2 things I am trying to do: Get an ingredient object out of my database of ingredients and set that ingredient object as a variable when creating a new recipe.
//This ingredient data was just for testing purposes - this still wouldn't work. This section is just trying to set an ingredient object as the Ingredient1 variable in the Recipe object.
InventoryItem theIngredient= new InventoryItem();
theIngredient.ID = 500;
theIngredient.Name = "Name";
theIngredient.Size = "None";
theIngredient.Stock = "None";
Recipe recipe = new Recipe()
{
ID = (maxPK == null ? 1 : maxPK.ID + 1),
Name = nameEntry.Text,
Ingredient1 = theIngredient
};
db.Insert(recipe);
This is the error I'm getting:
System.NotSupportedException Message=Don't know about PantryShopper.Models.InventoryItem
This isn't even exactly what I want to do...
What I want to do is to select the ingredient from a picker that is sourced by the database, then use the selected ingredient from the picker as the ingredient passed into the new recipe. However, on THAT I can't seem to access that item from the database AS an ingredient object. I was thinking in the way I convert that object into data for a database, can I get it back from the database as the original object version, or do I have to rebuild it (which is what I was trying to do as well)?
InventoryItem theIngredient= new InventoryItem();
ingredient1Picker = new Picker();
ingredient1Picker.ItemsSource = db.Table<InventoryItem>().OrderBy(x => x.Name).ToList();
stackLayout.Children.Add(ingredient1Picker);
inventoryItem = ingredient1Picker.SelectedItem;
Then set the ingredient to the currently selected item in the picker. However, I get the error: Cannot implicitly convert type 'object' to 'PantryShop.Models.InventoryItem,' An Explicit conversion exists (are you missing a cast?)
Anyway, this is my first post here. Any help is much appreciated! Cheers.