views:

24

answers:

0

Lets say I have two entities in my EF model Customer and Address which map to their respective Customer and Address tables in the db.

What I'd like to do is load up a Customer and their Address from the db into these entities but from different tables with slightly different schemas. They will then be saved to the Customer and Address tables as new records.

The options I assume I have of which none seem particularly elegant are below. Could anyone let me know if there is a better way or which of these is "best practice"?

1) Create two stored procedures. One to return the Customer and one for the Address. Load the entities separately using Function Imports by making the procs output fields in the exact format for the entities.

2) Create a single stored proc that returns a flattened CustomerAddress record and use the Mapping tool in the EF designer to produce my Customer and Address entities.

3) Use entirely separate Complex objects returned from one or more stored procs then use a library such as AutoMapper to map back into the Customer and Address.

Many Thanks

related questions