0

i have implemented table-per-hierarchy pattern into one of my entities and it looks like this:

this

atm, sube and acikhava entities are basically derived from mekan entity. there is no problem with these. well, what i want to know is, how should i implement this into CRUD views.

all of these entities have their own viewmodels, and mekan itself is not meant to be created by itself, the user can only create an atm, sube or acikhava, because mekan is an abstract entity. but i can't just set the model of view as the base entity and go on, because it isnt meant to be used that way, and throws errors.

now, should i behave this derived entities as completely different entities, and create separate views of them for every different action ? or find another way to achieve this.

thanks.

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Batu
  • 431
  • 1
  • 6
  • 17
  • 2
    Why can't you create a Mekan *view model* that contains atm, sube, and acikhava view models? – lucuma Jul 09 '14 at 14:37
  • @lucuma hm, let me try that – Batu Jul 09 '14 at 14:48
  • @lucuma so what should be the type of parameter on the controller ? how does mvc know that some form parameters actually belong to derived view model ? should i define all of the properties of derived view models, to mekan view model, than write a method to wrap it somehow to the correct view model. i am a little confused on this one. – Batu Jul 09 '14 at 15:47
  • I've added an answer with some details. – lucuma Jul 09 '14 at 15:57

1 Answers1

1

You could create a view model for Mekan:

public class MekanViewModel {
   public AtmViewModel Atm {get;set;}  // you said you already created these view models
   public SubeViewModel Sube {get;set;}
   public AcikhavaViewModel Acikhava {get;set;}
}

Your view would be strongly typed:

@model MekanViewModel

@Html.TextBoxFor(m=>m.Atm.Atm_TerminalNo)
etc

You're controller that would receive the data would receive MekanViewModel

[HttpPost]
public ActionResult Create(MekanViewModel mekan)
lucuma
  • 18,247
  • 4
  • 66
  • 91
  • well i completely forgot about what you show on the second code block. thank you @lucuma – Batu Jul 10 '14 at 13:58