0

I'm trying to optimize an NHibernate query:

var profile = dc.Profiles.FirstOrDefault(p => p.IdProfile == idProfile);

I would like it to load a collection of Rights. I did this:

var profile = dc.Profiles.Fetch(x => x.Rights).FirstOrDefault(p => p.IdProfile == idProfile);

The results were totally different from what I expected - instead of getting single Profile with rights I got single profile with single right!

How can I fix it?

kubal5003
  • 7,186
  • 8
  • 52
  • 90

1 Answers1

-1

You can use like this

var profile = dc.Profiles.Where(p => p.IdProfile == idProfile).Select(x => x.Rights);
Vitthal
  • 546
  • 3
  • 18
  • This is a totally different query. You select Rights collection instead of selecting a profile with associated Rights. – kubal5003 Mar 15 '13 at 12:19
  • Many Profiles with particular RIGHT > > `var profile = dc.Profiles.Where(p => p.Right== right).Select(p=>p.ProfileId);`
    > U can even make grouping `var profile = from profile in dc.Profiles where profile.Right == right group profile by profile.Rights into grp select grp.FirstOrDefault();
    – Vitthal Mar 15 '13 at 12:33
  • Thanks for trying, but once again you totally missed the point. The question is not about writing another query, but about fixing it to work properly. That might be an NHibernate bug too. – kubal5003 Mar 15 '13 at 17:02