Get a value from a collection in referenced document in index

29 views
Skip to first unread message

Haris Sheikh

unread,
May 24, 2013, 9:31:52 AM5/24/13
to rav...@googlegroups.com
Hi, is it possible to select a field in index using this statement:

CatalogueName = ((IEnumerable<LocalizedLabel>)LoadDocument<Catalogue>(item.CatalogueId).LocalizedName.LocalizedLabels).Select(x => x.LabelText).FirstOrDefault()

Here is my complete map definition:

Map = catalogueitems => from item in catalogueitems
                select new
                {
                    CatalogueId = item.CatalogueId,
                    CatalogueSectionId = item.CatalogueSectionId,
                    CurrencyCode = item.CurrencyCode,
                    ExchangeRate = item.ExchangeRate,
                    CatalogueSectionName = LoadDocument<CatalogueSection>(item.CatalogueId).Name,
                    ProductVersionName = LoadDocument<ProductVersion>(item.TargetProductVersionId).Name,
                    ProductId = LoadDocument<ProductVersion>(item.TargetProductVersionId).ProductId,
                    ProductVersionId = item.TargetProductVersionId,
                    SKU = LoadDocument<ProductVersion>(item.TargetProductVersionId).SKU,
                    CatalogueName = ((IEnumerable<LocalizedLabel>)LoadDocument<Catalogue>(item.CatalogueId).LocalizedName.LocalizedLabels).Select(x => x.LabelText).FirstOrDefault()
                };

Oren Eini (Ayende Rahien)

unread,
May 24, 2013, 10:19:56 AM5/24/13
to ravendb
That should work, yes. But this is probably an indication that you are doing something wrong.
You should NOT be doing so many LoadDocument.


--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Haris Sheikh

unread,
May 24, 2013, 10:25:09 AM5/24/13
to rav...@googlegroups.com
but when I query the index the field has null however Terms in studio displays proper value.

Haris

Oren Eini (Ayende Rahien)

unread,
May 24, 2013, 10:26:00 AM5/24/13
to ravendb
When you query the index, you are getting the results from the _document_.
If you want to do this in the results, do that in the result transfomer.

Haris Sheikh

unread,
May 24, 2013, 10:33:22 AM5/24/13
to rav...@googlegroups.com
This is how I am querying the index:

var returnValue = _documentSession.Query<CatalogueItemProductListItemWithProductFromCatalogueItem>().AsProjection<ProductListItem>().ToList();

and I am storing the value in index:
Store(x => x.CatalogueName, FieldStorage.Yes);

Oren Eini (Ayende Rahien)

unread,
May 24, 2013, 10:35:37 AM5/24/13
to ravendb
Go back three steps.
What is it that you are trying to do?

Haris Sheikh

unread,
May 24, 2013, 11:17:44 AM5/24/13
to rav...@googlegroups.com
I am trying to get a value from a collection in referenced document.
When I query the index, the value in null but Terms in studio is showing the value.

Oren Eini (Ayende Rahien)

unread,
May 24, 2013, 11:18:11 AM5/24/13
to ravendb
Do you need to query on that?

Haris Sheikh

unread,
May 27, 2013, 9:56:39 AM5/27/13
to rav...@googlegroups.com

I have found the issue that I am trying to project CatalogItem to ProductListItem which is basically a denormalized copy of CatalogItem.  

In index I query CatalogItem and uses LoadDocuments to populate denormalized fields in ProductListItem. These denorm fields are obviously not present in CatalogItem.  

Therefore when I use AsProjection(ProductListItem) on CatalogItems in query the denormalized fields are not populated because they were not present in CatalogItem.  

_documentSession.Query<CatalogueItemProductListItemWithProductFromCatalogueItem>().AsProjection<ProductListItem>().ToList(); 


Does this make any sense?

Kijana Woodard

unread,
May 27, 2013, 10:01:03 AM5/27/13
to rav...@googlegroups.com
Should you consider TransformResults:

Or, if using 2.5, a Results Transformer.
Reply all
Reply to author
Forward
0 new messages