NHibernate - Filling child entities from an unmaped class

I've a question about a code i've write to call a procedure using NHibernate, fill an unmaped entity and then fetch a list of child entities.

I'll show you an example. Three entities: house, interest, user

class house
string name; string title; string description;
list<interest> users;

I use the interest as a class for the relationship between house and users because i've a few additional properties like ranking, comment that i need to save.

class interest
house houseinterested;
user userinterested;
int ranking; string descriptions;

And the user class

class user
string name

Because i need to query all the houses withing an area range, i'm doing that calculations on a stored procedure (sending the lat/long), and then i return an extra property distance that i need to display on the views.

I dont want to map the distance to the table (because i just retrieve it, i never store that value), so i've created another entity similar to house but with the distance property (houseview), and i'm querying the procedure with CreateSQLQuery:

const string sql = "call imovel_within_area (:@orig_lat, :@orig_long, :@dist, :@take, :@skip, :@quartos, :@precomin, :@precomax)";
            var query = MvcApplication.Session.CreateSQLQuery(sql)
                .SetParameter("@dist", distancia)
                .SetParameter("@orig_lat", latitude) //-25.363882m
                .SetParameter("@orig_long", longitude) // 131.044922m
                .SetParameter("@take", resultados)
                .SetParameter("@skip", ((pagina-1 * resultados)))
                .SetParameter("@quartos", quartos.Value)
                .SetParameter("@precomin", precomin.Value)
                .SetParameter("@precomax", precomax.Value);

Now i want to fill the list of users interested.

foreach (var housein houses.List<Core.Domain.houseview>())
              house.Where(x => x.Id == house.Id).ToList().First().Interest =
              .Where(x => x.Id == imovel.Id).List().First().Interessados;

I never had to return a unmaped column from a query, so i'm not quite sure how to do this or if this is acceptable on performance issues.

I would really appreciate a few advices!



List<Core.Domain.houseview> houseviews = ...;

// load all wanted houses into session cache
    .WhereRestrictionOn(x => x.Id).In(houseviews.Select(hv => hv.Id).Tolist())
    .Fetch(x => x.Interessados).Eager

foreach (var view in houseviews)
    view.Interessados = Session.Get<house>(view.House.Id).Interessadoes;

Need Your Help

Generic type class defition

java class templates generics variables

There is a nice discussion of generics here