I’m trying to put together a ViewModel that will have a list of users and each user will have a list of locations.
The User table and Location table are joined together through another table that holds each respective ID and some other information. This table is essentially a many to many join table.
I’ve tried a few different viewModel approaches and they we’re severely lacking… What would be the best approach for displaying this type of information?
I’m trying to put together a ViewModel that will have a list of users
Share
I assume that the issue is that you want to be able to access the collection by either User or Location. One approach could be to use
ILookup<>classes. You’d start with the many-to-many collection and produce the lookups like this:Update:
Per your description, it seems like you don’t really need to have a full many-to-many relationship in your ViewModel. Rather, your ViewModel could have a structure like this:
If you wanted to avoid redundant
LocationViewModelobjects, you could pre-build a mapping between your Model and ViewModel objects:And then reuse these objects when populating your page’s ViewModel.