No, that was intended as HQL.

/Oskar


2009/10/13 Chris F <[email protected]>:
>
> Thanks Oskar,
>
> That will require LINQ to NH, which I can't execute at the moment,
> but I plan on upgrading project dependencies in the near future so
> I'll give it a shot when I do.
>
> - Chris
>
> On Oct 9, 6:10 pm, Oskar Berggren <[email protected]> wrote:
>> You seem to already have the manager loaded. By lazyload you pull in
>> all the secondary managed clients. Why are you then quering the
>> database again? Can't you just create the NameGuidDto yourself from
>> the already loaded Client instances?
>>
>> Hmm... lazy load for manager.PrimaryManagedClients and
>> SecondaryManagedClient should just be two queries I think, regardless
>> of the number of clients.
>>
>> But if you really don't need the Client instances at all, try if
>> something like this works:
>> select new NameGuidDto(sec_client.Name, sec_client.Guid)
>>  from Manager as manager
>>   join manager.Secondary as sec_client
>> where manager = :manager
>>
>> Combined with
>> select new NameGuidDto(sec_client.Name, sec_client.Guid)
>> from Client client
>> where client.PrimaryManager = :manager
>>
>> /Oskar
>>
>> 2009/10/9ChrisF<[email protected]>:
>>
>>
>>
>> > Someone on here must have an idea of how to do this better...
>>
>> > Please help if you can. Thanks.
>>
>> > On Oct 7, 6:08 pm,ChrisF<[email protected]> wrote:
>> >> Hello,
>>
>> >> My application has Clients and Managers, but a manager can be of
>> >> Primary (1-to-many) or Secondary (many-to-many) designation for a
>> >> Client. So, Manager has IList<Client> PrimaryManagedClients and
>> >> IList<Client> SecondaryManagedClients.
>>
>> >> I want to get all Clients for a Manager, regardless of the Manager's
>> >> designation. I've used to method below, but feel that it's probably
>> >> inefficient. How can I make it better? NameGuidDto is very simple: has
>> >> a string Name, and guid Guid.
>>
>> >> public IList<NameGuidDto> GetByManagerForDisplay(Manager manager)
>> >> {
>> >>     // First, grab all of the Clients where the Manager is
>> >>     // a Secondary. This method is inefficient because many
>> >>     // lazyloads are performed
>> >>     Guid[] clientIds = new Guid
>> >> [manager.SecondaryManagedClients.Count];
>>
>> >>     int count = 0;
>> >>     foreach (Client client in manager.SecondaryManagedClients)
>> >>     {
>> >>         clientIds[count++] = client.Id;
>> >>     }
>>
>> >>     ICriteria criteria = Session.CreateCriteria(typeof(Client))
>> >>                                 .Add(Restrictions.Disjunction()
>> >>                                     .Add(Restrictions.Eq
>> >> ("PrimaryManager", manager))
>> >>                                     .Add(Restrictions.In("Id",
>> >> clientIds)))
>> >>                                 .SetProjection
>> >> (Projections.ProjectionList()
>> >>                                     .Add(Projections.Property("Name"),
>> >> "Name")
>> >>                                     .Add(Projections.Property("Id"),
>> >> "Guid"));
>>
>> >>     // Transform results to NameGuidDto
>> >>     criteria.SetResultTransformer(Transformers.AliasToBean(typeof
>> >> (NameGuidDto)));
>>
>> >>     return criteria.List<NameGuidDto>();
>>
>> >> }
>>
>> >> I very much appreciate the help. Thanks in advance.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to