Asp.net MVC 4 model and LLBLGen entities

Posts   
 
    
RonENT
User
Posts: 28
Joined: 15-Oct-2012
# Posted on: 12-Dec-2012 00:54:45   

Q1) What are your recommendations for model definition relative to entity definition? 1. Reference entity in model or 2. Do not reference entity - create a 'flat' version of the entity that has only entity's properties (data). All data classes live in a business layer/dll that MVC/ui references. e.g., UserEntity -> UserData object

data flow is: a. fetch/read records from db into entities b. populate data object(s)

c. use data objects in UI - update them/create them , etc.

d. usiing data object(s), populate entities e. save entities to db

Q2) If you recommend (1), point out issues/limitation, and weaknesses. e.g., maybe entities do not support dependency injection

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Dec-2012 06:27:35   

RonENT wrote:

Q1) What are your recommendations for model definition relative to entity definition?

Both are valid. If you are doing straight forward mapping perhaps I would suggest using LLBLGen Entities because you don't have to worry about tracking field changes, re-mapping to DTOs, etc. In MVC you have to use a ModelBinder that translate the Entities into ViewModel data and viceversa. Brian Chance wrote a LLBLGenModelBinder. You can see it here with an example: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=19731&StartAtMessage=0&#111280

RonENT wrote:

Q2) If you recommend (1), point out issues/limitation, and weaknesses. e.g., maybe entities do not support dependency injection

I'm using the LLBLGenModelBinder in my apps and I'm pretty happy with it. There are some things you have to map additionally in order to have it working. One of them is the .IsNew property, you can include it as a hidden input in your view. If you don't you have to set it in your controller: set it to true is you are on the Add action, or false if you are on the Edit action.

If you go on your 2nd option, you have to do the mapping by yourself, so you will end up doing a ModelBinder. So why not use the Brian's one and improve it if needed.

David Elizondo | LLBLGen Support Team