How to overcome viewModel impedance mismatch?

I am puzzled.

I have a linq-to-sql model that is a mirror of a database table

(Id, CustomerId, RegionId,...N), 

nothing interesting, all foreign keys. Now I need to view this data in my asp.net view. I am creating a ViewModel

(Id, CustomerId, Customer, RegionId, Region, CustomersSelectList, RegionsSelectList). 

Obviously, viewmodel is a superset of the linq-to-sql model.

Now, how do I convert one to another? I use automapper, but I wonder how to find good patterns for getting missing data.

I see possible solutions:

  • Create a 3rd class that will be the l2s + model with the combined values ​​and populate this class by combining and projecting. Then open this class in my view model.

  • Return anonymous classes via projection and map them to view modes through automapper (not very clean).

  • db ( - , ).

, , L2S ( ), - .

, , ? ?

.

UPDATE: . . db , L2S ( db), ViewModel "" db.

sql- linq ViewModel?

- ( linq ) linq sql, ViewModel?

L2S -, - L2S ORM?

+3
1

automapper, , , , . -, automapper , . , , , .

+1

Source: https://habr.com/ru/post/1723347/


All Articles