Question

I am using FluentNHibernate to access to my database. I would like to implement next - just required properties of my entity should be filled. By example, in one case all properties should be filled, in second case repository should return entity with ID and Name properties only. Does it make sence?

I see point when I can implement a few mappings for entity - every mapping according to case. Then I get a few ISessionFactory'ies - repository uses required ISessionFactory to cover required case. Hmm.. but I am not sure that it is correct solution.

Was it helpful?

Solution

just create specialised DTOs Viewmodels for each scenario and select directly into them

using NHibernate.Linq;

var user = session.Query<User>()
    .Where(user => user.Name == someName)
    .Select(user => new LoginUser(user.Id, user.Name))
    .FirstOrDefault();

OTHER TIPS

What are you looking for is called 'projections', but projection object should be different object, not the entity itself. NHibernate supports projections out of the books. Have a look at docs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top