Hi Krzysztof, Thanks! I tried your suggestion and works great.
Thanks again! =) Marco Antonio http://www.paperscrap.com.br/ twitter: @marcoaoteixeira ________________________________ De: Krzysztof Koźmic <[email protected]> Para: [email protected] Enviadas: Terça-feira, 18 de Maio de 2010 2:16:37 Assunto: Re: [AR] FindAll(ICriterion[]) returns more results than expected. You probably have outer join there. In this case use DistinctRootEntityTransformer, to filter out duplicates. Krzysztof On 2010-05-18 03:19, Marco Antonio wrote: > Hi all, > > I'm having a bad time with FindAll(ICriterion[]). Well, maybe I'm > doing something wrong too...that's more probably to happen. But, > anyway... > > I have a method called FilterPostByRequest, in my webapplication. This > method extract all parameters from Request.QueryString and creates a > list of ICriterion to pass to FindAll method, so, it's suposed to > bring back, from database, all records that correspond to the filter. > In my database, the queried table, has 30 records...but when the app > execute the method (FindAll(ICriterion[])) it returns 41 records > (???)...something is not right. Can, anyone, help me with this > question?? Thanks! > > Note...FindAll() (without parameters) returns 30 records, as expected. > > I'm using MySql, AR 2.1.2, and my models, all collections (lists) > using lazy load. > > The method (FilterPostByRequest) > > private IEnumerable<Post> FilterPostsByRequest(HttpRequestBase > request, bool onlyPublished) > { > long categoryId = 0; > string title = string.Empty; > DateTime dateCreatedFrom = DateTime.MinValue; > DateTime dateCreatedTo = DateTime.MinValue; > State state = State.None; > IList<ICriterion> criterions = null; > > categoryId = request.QueryString.Get<long>("category.Id"); > title = request.QueryString.Get<string>("post.Title"); > dateCreatedFrom = > request.QueryString.Get<DateTime>("post.DateCreated.From"); > dateCreatedTo = > request.QueryString.Get<DateTime>("post.DateCreated.To"); > state = (State)request.QueryString.Get<int>("post.State"); > > criterions = new List<ICriterion>(); > > if (categoryId != 0) > criterions.Add(Expression.Eq("Category.Id", categoryId)); > > if (!string.IsNullOrEmpty(title)) > criterions.Add(Expression.InsensitiveLike("Title", title)); > > if (dateCreatedFrom != DateTime.MinValue&& dateCreatedTo != > DateTime.MinValue) > criterions.Add(Expression.Between("DateCreated", dateCreatedFrom, > dateCreatedTo)); > > if (!onlyPublished) > { > if (state != State.None) > criterions.Add(Expression.Eq("State", state)); > } > else > { > criterions.Add(Expression.Eq("State", State.Normal)); > } > > return Post.FindAll(criterions.ToArray()); // Database has 30 > records, but this method return 41 (ex.). FindAll() works fine. > } > > p.s.: sorry about the "bad english"! =) > > -- You received this message because you are subscribed to the Google Groups "Castle Project Users" 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/castle-project-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Castle Project Users" 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/castle-project-users?hl=en.
