I have two objects that are linked by a foreign key relationship and I use DataModel to map the objects:
Event:1——*:Asset
I wrote a query that fetches all assets for a given [eventPublicId]
List<Asset> assetList =
ReliableExecution.RetryWithExpression<Event, List<Asset>>
(u => u.FirstOrDefault(x => x.PublicId == eventPublicId).Assets.ToList()).ToList();
My problem is that I had to call ToList() twice and this looks awkward. Also I had to use FirstOrDefault, but when I tried to use [Where] or anything else, it didn’t compile.
Is there any other better way how this code can be rewritten?
This is RetryWithExpression signature for reference:
public static TValue RetryWithExpression<T, TValue>(Func<ObjectSet<T>, TValue> func, Int32 retryInfiniteLoopGuard = 0)
where T : class
You specify that the
funcparameter should return aList<Asset>, so the navigation propertyevent.Assetsdoes not fit the bill: It is anEntityCollection<Asset>, which is not implicitly convertible to the delegate return type. The explicit conversionToList()creates the specified type.Technically, to get rid of the ToList, you should use
but I don’t know if that meets your functional requirements.