So I have something like this:
List<Entity2> list = new List<Entity2>();
Action<Entity2> adder= (z) =>retVal.Add(z);
Func<Entity1, Entity2> getter = (x) =>repository2.GetSingle(f=>f.ID == x.Entity2ID);
repository1.Get(q=>q.UserName).Foreach(adder(getter(???))); //Need to pass Entity1 to the delegate in here
E开发者_运维知识库ntity1 Has a reference field called Entity2ID, but there is no explicit relationship set in the linq for certain reasons.
SO the idea is to locate entity2 for every entity1 using the getter delegate since they have no explicit relationship and just add the matching entity2 to the list using the ForEach extension on the collection of entities1.
My question is how to I get a hold of the object I am performing the ForEach on?
repository1.Get(q=>q.UserName).Foreach(x => adder(getter(x)));
Alternatively, you should be able to do this:
retval.AddRange(repository1.Get(q=>q.UserName)
.Select(x => repository2
.GetSingle(f=>f.ID == x.Entity2ID)));
精彩评论