I was using
but discovered that its was loading all the objects from DB to select the 2 elements I was searching for !!!!!
(is it normal ???? )
Then I tried something as
_myPartRepository.Table.Select( c => _contentManager.Get<myPart>(c.Id) ).ToList();
but I am receiving sporadically exceptions related to the session being closed ?
(Orchard is missing a documentation page 'Queries in Orchard' with samples)
May 11, 2013 at 11:37 PM
May 12, 2013 at 8:11 AM
Edited May 12, 2013 at 8:15 AM
I will give a look and make a feed back, thanks.
What do you think about this very common request which loads all DB in memory ? Isn't there an optimization problem ?
This related to all Orchard module that may behave like this: apparently the job is done but in the background, the paid price is global site inefficiency.
All these action filters triggered with no reason; all these duplicate read....
Actually my site is not started, I get 500 items loaded....
May 12, 2013 at 9:42 AM
Edited May 12, 2013 at 12:07 PM
This demo module is for real beginners. It is a good starting point for Orchard.
( I would suggest you move more queries in the related Services )
Concerning queries in ContentAdminController, they simply appear as tricks to obtain some result.
I am more trying to undertsand the global logic of Querying under Orchard with questions as:
- How ContentManager Ids are generated according the various tables
- Which 'structrural tables' are permanently loaded in Orchard if there are.
And, related, which tables are queried to find a content item with its id between the Settings_XXX, Framework-XXXX and Common_XXX tables containing the real Orchard data dictionary
- Are there several systems of querying inside Orchard and what is the difference
- How Orchard/NH is using the Session, how to use the session transaction. Could we do 'ghost' requests, nolock requests or locking requests, commit, partial commit, rollback, etc.
Is NH Session totally fitted to HTML Request Session / ASP.NET Request? Coud we have several NH sessions in one HTML Request ? is NH using Session State for continuity ? etc.
- Difference between' myRecordRepository' direct usage and Contentmanager
- Is it possible and how to query for a single part record (without the containing contentItem), or is NH always loading a content item.
It seems there are 2 kind of queries in Orchard:
- find a contentitem from its contained part values (find an invoice by it value)
- find a group of content items based on relations between their content (exemple: find all the invoice related to a product and a customer)
How to do this in Orchard/NH ?
- As an old SQL user I am used to the SQL join syntax, doing outer, inner, left outer etc, how to apply this to Orchard contentitems, how to mix this with tables which are not ContentPart related.
How to make a query implying different ContentItems (exemple: Users, Orders, OrdersDetail)
- What is the syntax benefits of having Part and corresponding Record in syntax like this : Query<MyPart,MyPartRecord>(). Why this heavy writing, why couldn't we forget mentioning the MyPartRecord as it could be infered from the Part in 99% of situations
- This one may be more related to LinQ: understanding when NH really apply the Query is also a question of importance: queries are used by NH as pure objects but they could contain error, and we only discover it later when NH try to get the results (sometime
with really poor error message as Index out of values...) . Understanding when this occurs is important. For exemple you can't apply some select using c# syntax on SQL, but you can on the results. How to force NH to execute the query, what is the cost in term
of network load between IIS and SQL, etc.
- How is working NH Cache (SysCache ?) ? I discover frequently in modules codes some multiple loading of the same object, and each time NH seems to do same quantity of work, isn't there a cooler API to check 'in NH' if something is already there ?
How is managed the flushing of new objects, are in a same transaction, new/updated objects flushed in order to appear as present for next queries ? Etc.
- Missing also a general Q&A for Orchard querying:
- what not to do (as the Lis<MyPart> I discovered)
- How to apply classical selects on strings, what is working and what not ( String.Equals nok, case insensitivness, contains, etc.)
Answering these could be a good starting point and help many users ?
May be simply copying this .... with answers in the Orchard documentation ?