s/WFC/WCF

    Diego


On Mon, Aug 30, 2010 at 10:43, Diego Mijelshon <[email protected]>wrote:

> Pseudocode:
>
> var receipts = LinqCriteriaSqlOrHqlQueryForReceiptsOnly()
>                      .FilteringByIsNotSynchronizedAndIsClosed()
>                      .InAnyOrderThatYouWant()
>                      .SetMaxResults(200) // or .Take(200) for Linq
>                      .List<Receipt>()
> var ids = (from receipt in receipts select receipt.Id).ToList();
> var irrelevant = QueryForReceiptsFetchingPayments()
>                       .FilteringByIdIn(ids)
>                       .List()
> var irrelevantToo = QueryForReceiptsFetchingEntries()
>                            .YouGetTheIdea()
>                            .YouCanCombineTheseTwoQueriesWithFuture()
>
> Now, if you are going to use WFC, it's better to create DTOs, regardless of
> how you do the queries.
>
>     Diego
>
>
>
> On Mon, Aug 30, 2010 at 05:48, Niclas Pehrsson <[email protected]> wrote:
>
>> Well its a lot.
>>
>> Receipt has two collections, receipt entries and payments.
>> I want to load top 200 where the receipts is closed and not
>> synchronized.
>> The entities will be sent over wcf so lazyloading isn't anything to
>> use it is best to load them all at the same time.
>> We are using NHibernate 2.1 right now.
>>
>> Receipt.IsSynchronized
>> Receipt.IsClosed
>> Receipt.Payments
>> Receipt.Entries
>>
>> How would I do this on the most efficient way?
>>
>> On Aug 28, 12:55 pm, Diego Mijelshon <[email protected]> wrote:
>> > ONE QUERY PER COLLECTION, not ONE QUERY PER COLLECTION PER RECORD.
>> > If you have one filtered query with two collections, that's 3 queries
>> TOTAL,
>> > regardless of the record count.
>> >
>> > Future allows you to reduce the roundtrips (the number of queries is
>> still
>> > the same), but you can't combine the first query and the others if
>> you're
>> > paging.
>> > You can still use it for queries other than the first, which brings the
>> > roundtrip count to 2 regardless of how many collections or records you
>> are
>> > loading.
>> >
>> >     Diego
>> >
>> > On Sat, Aug 28, 2010 at 04:55, Niclas Pehrsson <[email protected]>
>> wrote:
>> > > Well that means a lot of queries if MaxSize is 200.
>> > > But maybe it is the only way to do it.
>> >
>> > > Are there any example of this scenario with Criterion?
>> > > I guess the use of Future is needed, you want to get the root entity
>> > > loaded with its collections as result.
>> >
>> > > On Aug 27, 8:08 pm, Diego Mijelshon <[email protected]> wrote:
>> > > > The answer is right there: "two totally separate queries, first to
>> get
>> > > just
>> > > > the entities, then to load the related associations"
>> >
>> > > > First, one paged query without fetching the collections, then one
>> query
>> > > per
>> > > > collection, filtering with the Ids of the first query.
>> >
>> > > >     Diego
>> >
>> > > > On Fri, Aug 27, 2010 at 09:49, Niclas Pehrsson <[email protected]>
>> > > wrote:
>> > > > > Well it wont work :(
>> >
>> > > > > Ayende repsonded to an comment with this
>> > > > > "SetMaxResults, but that might cause issues with the loading.
>> > > > > At that point, I might want to execute two totally separate
>> queries,
>> > > > > first to get just the entities, then to load the related
>> associations.
>> > > > > "
>> >
>> > > > > So how can I solve this?
>> > > > > Its a bit annoying, I want to load 200 hundred of thousands, and I
>> > > > > want to avoid 200+200 select queries.
>> > > > > Any other approaches?
>> >
>> > > > > On Aug 26, 3:03 pm, Diego Mijelshon <[email protected]>
>> wrote:
>> > > > > > SetMaxResults and SetFetchMode on _collections_ don't get along.
>> >
>> > > > > > Suggested read:
>> > > > >
>> http://ayende.com/Blog/archive/2010/01/16/eagerly-loading-entity-asso.
>> > > ..
>> >
>> > > > > >     Diego
>> >
>> > > > > > On Thu, Aug 26, 2010 at 04:50, Niclas Pehrsson <
>> [email protected]>
>> > > > > wrote:
>> > > > > > > Hi I have an query that looks like this.
>> >
>> > > > > > >            Return (From receipt In _session.Linq(Of
>> > > > > > > PointOfSale.Receipt)() _
>> > > > > > >                            Where receipt.IsClosed AndAlso Not
>> > > > > > > receipt.IsSynchronized _
>> > > > > > >                     Select receipt).Take(25).ToList()
>> >
>> > > > > > > Or
>> > > > > > >            Dim criterion = _session.CreateCriteria(Of Receipt)
>> > > > > > > ().SetMazSize(25).Add(Expression.Eq("IsClosed", True)) _
>> > > > > > >                .Add(Expression.Eq("IsSynchronized", False)) _
>> > > > > > >                .SetFetchMode("Payments", FetchMode.Eager) _
>> > > > > > >                .SetFetchMode("ReceiptEntry", FetchMode.Eager)
>> >
>> > > > > > >            'Return criterion.List(Of PointOfSale.Receipt)()
>> >
>> > > > > > > Both of them first asks the database för the first query
>> options
>> > > > > > > IsClosed and Not IsSynchronized, and then It creates an select
>> N+1
>> > > for
>> > > > > > > each element. How can I do this better so it will be just one
>> or
>> > > three
>> > > > > > > queries that selects top 25 entities?
>> >
>> > > > > > > --
>> > > > > > > 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]<nhusers%[email protected]>
>> <nhusers%[email protected]<nhusers%[email protected]>
>> >
>> > > <nhusers%[email protected]<nhusers%[email protected]>
>> <nhusers%[email protected]<nhusers%[email protected]>
>> >
>> >
>> > > > > <nhusers%[email protected]<nhusers%[email protected]>
>> <nhusers%[email protected]<nhusers%[email protected]>
>> >
>> > > <nhusers%[email protected]<nhusers%[email protected]>
>> <nhusers%[email protected]<nhusers%[email protected]>
>> >
>> >
>> > > > > > > .
>> > > > > > > For more options, visit this group at
>> > > > > > >http://groups.google.com/group/nhusers?hl=en.
>> >
>> > > > > --
>> > > > > 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]<nhusers%[email protected]>
>> <nhusers%[email protected]<nhusers%[email protected]>
>> >
>> > > <nhusers%[email protected]<nhusers%[email protected]>
>> <nhusers%[email protected]<nhusers%[email protected]>
>> >
>> >
>> > > > > .
>> > > > > For more options, visit this group at
>> > > > >http://groups.google.com/group/nhusers?hl=en.
>> >
>> > > --
>> > > 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]<nhusers%[email protected]>
>> <nhusers%[email protected]<nhusers%[email protected]>
>> >
>> > > .
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/nhusers?hl=en.
>>
>> --
>> 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]<nhusers%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/nhusers?hl=en.
>>
>>
>

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