NH can provide the data transtlation, unit of work, and validation (the NH validation project, or something like that). for mapping entities to view models I recommend AutoMapper. for mapping viewmodels to domain objects, if the domain is rich then this is usually best handled with hand rolled code.
with NH you map your domain to the database (xml, fluent nh, active record). these mappings are consumed by the configuration object. the configuration object builds a session factory. the session factory is like your context. an appilication should have a singleton instance of the session factory. from the session factory you open/dispose of sessions. sessions are your unit of work. the session is where all your entity mapping, 1st level caching, concurrency, etc work is done. there are many tutorials only line that demonstrate this. I haven't worked with NH validation directly, but what I read about it you again have a variety of choices to define the validation rules. plug these rules into the NH configuration object and when the session factory is built validation is ready to go. when I first started with NH I wrapped all my session calls in a repository object. I found this didn't really provide me with much value and dropped the repository to access the session directly. if I need reusable queries I create subclass of DetachedCritiera and use them instead. automapper is very simple to use and pretty self explanatory. basically you tell the mapping engine at startup what the source and destination objects are. after that you call var destination = MappingEngine.Map<S, D>(source) On Sep 24, 6:27 am, shapper <[email protected]> wrote: > Hello, > > I have been trying to use Entity Framework with a Validator and a > Mapper projects in MVC and I have huge problems. > > I am considering move everything to NHibernate. > Before that could someone, please, clarify me on the following? > > 1. I need to create a Context with its Entities and Relationships from > a SQL Database. > I have One to Many and Many to Many relationships. > > 2. I need to implement Unit of Work and Repository pattern on those > Entities. > > 3. I need to map the Entities to Models (and vice versa) that are more > appropriated to the MVC project. > > For example, map: > > public class DocumentCreate { > public String Title { get; set; } > public HttpPostedFileBase File { get; set; } > public String LevelId { get; set; } > public List<Int32> SubjectsIds { get; set; } > } > > To an Entity Document where: > > String Title > String Title > HttpPostedFileBase File > Byte[] File > String LevelId > This is the Id of a Level to be associated to a > Document (1 to 1 Relationship) > List<Int32> SubjectsIds > This contains the SubjectsIds that > should be related to the Document (1 to * Rel) > > 4. Need to validate DocumentCreate > > I need to validate DocumentCreate with Fluent Validation before > the map to Document Entity occurs. > > I have a lot of problems with EF and the two open source projects so I > hope someone can give me some feedback on this to decide if I move to > NHibernate tools or not. > > Thank You, > Miguel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
