This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
In my app, i have an Item entity that has both costs and prices associated. For the Price entity, i have a partial class that contains some extra transient properties, such as Price - Cost etc.. so, when i load in an Item record, for each price record, i get the latest cost record for that price and do the calculations. i.e.
var cost_records = from r in Item.Costs
where r.EffectiveDate <= _effectiveDate
orderby r.EffectiveDate descending, r.StartDate descending, r.Id descending
select r; and then use the first record (if any) problem is that i am getting an error on the Item.Prices... [System.InvalidOperationException] = {"There is already an open DataReader associated with this Command which must be closed first."} i have had a look through the support forums and found the reason behind this in a reply by Ivan. is there a simple way around this, using the partial class - or do i need a separate routine to load and calculate the costs for the prices ?? thx |
|
|
Yes, if you have a calculated property that requires access to other entities, you'll need to do that after the current query has completed. For example, lazily calculate the property the first time it is accessed. A possible way around it is to create a temporary unit of work within the AfterLoad override, and perform the query in that (because that will use a new connection): var cost_records = from r in tempUow.CostRecords but this may not work well for large numbers of entities because it will result in spinning up a lot of connections. Also you will need to extract the desired value(s) immediately from this query -- because the UOW is temporary you can't allow deferred evaluation -- and you will want to extract only scalar values, because you don't want to have entities hanging around that are associated with a temporary UOW. Hence e.g.: var cost = (from r in tempUow.CostRecords |
|