I would like to make app for restaurant. It´s about calculation recipes.
I have domain classes: - Ingredient - Recipe - RecipeItem
Recipe has List of RecipeItem.
RecipeItem could be Ingredient but also Recipe.
So I'm using Interface IItem with 2 properties(Id, Name). If I use Interface in my class, db generator ignore this field.
Look at my classes here:
public class Ingredient : IItem
{
public int Id { get; set; }
public string Name { get; set; }
public double Price { get; set; }
}
public class Recipe : IItem
{
public int Id { get; set; }
public string Name { get; set; }
public List<RecipeItem> RecipeItems { get; set; }
}
public class RecipeItem
{
public int Id { get; set; }
public IItem Item { get; set; }
public double Quantity { get; set; }
}
CodeFirst automaticly generate for me database with tables above.
I would like to have database table RecipeItem looks likes:
> Id
> Quantity
> Recipe_Id - FK of Recipe ID
> RecipePointer - Nullable FK of specific Recipe
> IngredientPointer - Nullable FK of specific Ingredient
But there are only:
> Id
> Quantity
> Recipe_Id - FK of Recipe ID
If I put into RecipeItem for example Ingredient, than Id of Ingredient will be inserted to IngredientPointer.
I would like to use FLUENT API for mapping but I don't know how.
I don't know if is possible what I want, or if is any better way how to solve my problem.
I watched already CodeFirst video on Pluralsight and I browse in forums but I can't find answer.
Thank you for any help.