Very cool!  However, this is for an open source project so I don't want to
add any more external dependencies to the project, since users will have to
download those too.  Thanks!

Mike


On Fri, Jan 24, 2014 at 12:44 PM, Fran Knebels <[email protected]> wrote:

> you might want to try using MoreLinq.  MoreLinq adds a DistinctBy
> extension method.
>
> I setup a little test.
>
>             using (ISession session = SessionFactory.OpenSession())
>             {
>                 using (ITransaction tx = session.BeginTransaction())
>                 {
>                     var person = new Person { Name = "Fred" };
>                     session.Save(person);
>                     var person1 = new Person { Name = "Fred" };
>                     session.Save(person1);
>                     var person2 = new Person { Name = "Fred" };
>                     session.Save(person2);
>                     var person3 = new Person { Name = "Fred" };
>                     session.Save(person3);
>                     var person4 = new Person { Name = "Fred" };
>                     session.Save(person4);
>
>                     session.Flush();
>
>                     var personList = (from p in session.Query<Person>()
> select p).DistinctBy(x => new { x.Name }).ToList();
>
>
>
>
>
>                     tx.Rollback();
>                 }
>             }
>
> personList return 1 person.
>
>
> On Fri, Jan 24, 2014 at 3:31 PM, Mike Christensen <[email protected]>wrote:
>
>> I basically want this query:
>>
>> select distinct name from mytable order by name;
>>
>> The following works, but I find it rather overly complex:
>>
>> var formSyn = session.QueryOver<Models.NlpFormSynonyms>()
>>    .OrderBy(p => p.Name).Asc
>>    .Select(s => s.Name)
>>
>>  
>> .RootCriteria.SetProjection(Projections.Distinct(Projections.Property<Models.NlpFormSynonyms>(p
>> => p.Name)))
>>    .List<Models.NlpFormSynonyms>();
>>
>>
>> I've also tried this:
>>
>> var formSyn = session.QueryOver<Models.NlpFormSynonyms>()
>>    .OrderBy(p => p.Name).Asc
>>    .Select(s => s.Name)
>>    .TransformUsing(Transformers.DistinctRootEntity)
>>    .List();
>>
>> Which looks nicer, but causes the runtime exception:
>>
>> An unhandled exception of type
>> 'NHibernate.Exceptions.GenericADOException' occurred in NHibernate.dll
>>
>> Additional information: Unable to perform find[SQL: SQL not available]
>>
>> What's the best way to do this?  Thanks!
>>
>> Mike
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "nhusers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/nhusers.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to