I didn't because it was a 5 minute test, but looking at the DistinctBy code it looks like it's going to materialize the list and then filter it. So it's doesn't integrate with nhibernate. It's just spinning through the list and bucketing into a hashset per the, distinct properties. So large lists are going to kill performance.
On Fri, Jan 24, 2014 at 4:12 PM, Mike Christensen <[email protected]>wrote: > I'm also a bit curious if this extension actually integrates with > NHibernate (and adds "distinct" into the SQL statement) or if it grabs all > the data, then filters the distinct values after the data has been > materialized. Did you actually look at the generated SQL code when you ran > your test? > > > On Fri, Jan 24, 2014 at 1:05 PM, Mike Christensen <[email protected]>wrote: > >> Perhaps if I were using a bunch of Morelinq extensions, but not worth it >> for just this one. I'd rather find a good native NH way to do this. After >> all, I can just wrap this up into an extension method.. >> >> >> On Fri, Jan 24, 2014 at 1:04 PM, Fran Knebels <[email protected]> wrote: >> >>> the dll for morelinq is 57kb. >>> >>> I don't know your deployment situation, but what about ILMerge'ing all >>> the dll/exe into a single exe if you are deploying an exe. >>> >>> >>> On Fri, Jan 24, 2014 at 3:55 PM, Mike Christensen <[email protected]>wrote: >>> >>>> 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. >>>> >>> >>> -- >>> 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.
