tags:

views:

33

answers:

1

Does Hibernate + NhibernateLINQ support projection of inner objects.

for eg. when I try the following I get an Index out of bounds exception on Patient object on the call to Queryable.ToList()

            var registrations = from r in _session.Linq<Domain.Registration>().Expand("Patient") select r;
        var queryable = registrations.Select(
            r => new { r.Id, r.AccountNumber, r.DateAdded, r.DateUpdated, r.Patient.FamilyName, r.Patient});
        var list = queryable.ToList();

        var workListItems = new List<WorkListItem>();
        foreach (var anonymous in list)
        {
            var w = new WorkListItem
            {
                Id = anonymous.Id,
                ClientAccountId = anonymous.AccountNumber,
                DateAdded = anonymous.DateAdded,
                DateUpdated = anonymous.DateUpdated,
                Patient = anonymous.Patient
            };
            workListItems.Add(w);
        }
        return workListItems;
+1  A: 

The legacy contrib provider has problems with this kind of query.

The new integrated provider in NHibernate 3 handles them without problems.

As of 2010-09-30, Alpha3 is quite stable (with most efforts directed to improving the Linq provider even more), and a GA release is expected before the end of the year.

Diego Mijelshon
thanks, just got Alpha3 release. where can I get the Nhibernate.Linq dlls.
vikram nayak
It's integrated (no additional files). Just use session.Query<Entity> instead of session.Linq<Entity>
Diego Mijelshon
Thank you, that worked!
vikram nayak