-1
  1. There is a model class called Review.

  2. ReviewModel is used from StoreModel and Menu model.

In StoreModel.cs

[Table ("Stores")]
public class StoreModel
{
    [Key]
    public int Id { get; set; }

    public string StoreName { get; set; }
    public string StoreShortDescription { get; set; }
    public string StoreFullDescription { get; set; }
    public string StoreAddress { get; set; }

    public ICollection<MenuModel> Menus { get; set; }
    public ICollection<ReviewModel> Reviews { get; set; }

    public StoreModel ()
    {
        Menus = new Collection<MenuModel> ();
        Reviews = new Collection<ReviewModel> ();
    }
}

in MenuModel.cs

[Table ("Menus")]
public class MenuModel
{
    [Key]
    public int Id { get; set; }

    public string MenuName { get; set; }
    public string MenuShortDescription { get; set; }
    public string MenuThumbnailUrl { get; set; }
    public int MenuPrice { get; set; }

    public ICollection<ReviewModel> MenuReviews { get; set; }

    public MenuModel ()
    {
        MenuReviews = new Collection<ReviewModel> ();
    }
}

In this case, how should I implement this?

  • Create a base ReviewModel class and have 2 subclass (StoreReview, MenuModel)

or

  • Use ReviewModel for both StoreModel and MenuModel (how?)

or

  • thoughts?
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
softmarshmallow
  • 1,034
  • 2
  • 16
  • 31
  • Please avoid asking question that ask for opinions, it's off-topic: _Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise._ – Tseng Jul 25 '17 at 06:00

1 Answers1

0

If the ReviewModel properties are the same in both (StoreModel and MenuModel) there is nothing special to do, just use ReviewModel as it is being used in your shown code for both models. In any case, just add an enum property to ReviewModel to know wether it is a StoreModelReview or a MenuModelReview. Your ReviewModel might look like this: (creating many 2 many relationship)

[Table ("Reviews")]
public class ReviewModel
{
    [Key]
    public int Id { get; set; }

    public ReviewEnum Type { get; set; }



    public ICollection<MenuModel> Menus{ get; set; }
    public ICollection<StoreModel> Stpres{ get; set; }

}