When you follow the exemple for 1-N relations, address-state, you get a StateRecord in the AddressPart ?
In my case, I have a situation where 1 part contains 3 records from other Parts: a product price (productpricelist), attached to a currency( CurrencyPart ), a product,(ProductPart) and a Price List (PriceListPart).
I follow the doc sample, only creating the columns for the 'external indexes' in the product price table.
It works as expected, reading the ProductPriceListPart, I get the records automatically filled.
I have situations where from a list of Price Lists, selecting one I display all the product prices for a selected currency.
The query to select the prices is logically like this.
Get the Price List Part using _contentManager.Get<PriceListPart>(PriceListId);
Then select the currencies already existing in the Prices for this Price List, here it became lees obvious
public IEnumerable<CurrencyPartRecord> GetCurrencies(PriceListPart PLPart) {
return _contentManager
.List<ProductPriceListPart>()
.Where(p => p.PriceList.Id == PLPart.Id)
.Select( p => p.Currency )
.Distinct();
}
Here I get a list of currency records. with the Id in one of these currencies, I select the PriceListParts using it with
{
return _contentManager.Query<ProductPriceListPart, ProductPriceListPartRecord>()
.Where(p => p.PriceList.Id == PLPart.Id && p.Currency.Id == cpart.Id)
.List()
.Select( prop => prop.As<ProductPriceListPart>());
}
On this step I have ProductPriceList content parts, but each contains a ProductPartRecord, and if, in the template displaying this list of elements, I want to insert an Url.ItemDisplayUrl(...) I need a ContentItem (all the Html and Url nice extenders don't work with records)., So the only solution I found have been to reload in a loop all the productPart and insert them in a Dictionary<int,ProductPart> and access it in the loop building the html table.
Same problem for currencies, I have to reload them with the ids in the list of CurrencyPartRecords.
Seems that I am doubling the database access, even if the NH cache (?) could do something nice, but each cache have its limits in term of number and size it manages.
Is it the correct way to deal with this in Orchard ?
|