|
|
I am trying to access the items of a list but I've been unsuccessful. I find it odd that the items in the list with containeable part are able to know who is the container but I can't seem to find these items in the list itself.
Any thoughts on this?
Thanks in advance,
João Reis
|
|
|
|
How are you trying to access them, can you show us the code that isn't working?
|
|
Nov 24, 2011 at 1:03 PM
Edited Nov 24, 2011 at 1:09 PM
|
I got it to work now by using the following:
var List = _contentManager.Query("CTType").List();
var parentId = part.ContentItem.Id;
var Highlight = (from News in List
where (from parts in News.Parts where parts.As<CommonPart>().Container.ContentItem.Id == parentId
select parts.Id).Count() > 0
&& News.IsPublished()
orderby News.As<CommonPart>().PublishedUtc descending
select News).First();
But I feel like there has to be some other way to get it
|
|
|
|
The problem there is that you start by calling List() which enumerates the entire query in memory before you've even filtered. The News.IsPublished() check is also redundant because ContentManager by default queries for published content unless you specify
VersionOptions to say otherwise.
You can do a join query with ContentManager like this:
var query = _contentManager.Query("CTType").Where<CommonPartRecord>(c=>...)
|
|
|
|
That does make sense and confirms my first impression, thank you very much.
|
|
|
|
How can i use this query for termcontentitem view to sort then by created date?
I am trying
var list1 = contentManager.Query("list").OrcderBy(list => list.As<CommonPart>().CreatedUtc);
but it's not working.
|
|
|
|
Don't use As<> within the OrderBy, that'll create performance problems and probably errors. Instead use OrderBy<CommonPartRecord>(c=>c.CreatedUtc)
|
|
|
|
Thanks for reply but It's throwing error CommonPartRecord could not be found.missing assembly reference
|
|
|
|
add the reference in project to Orchard.Core if I am not mistaken, it's the dependency that is missing
|
|
|
|
Do I have to add it in web.config in core?
what should I write there?
|
|
|
|
Not write. In your module add a reference to Orchard.Core.
Read this:
http://msdn.microsoft.com/en-us/library/f3st0d45%28v=vs.80%29.aspx
|
|