I want to do a simple lambda expression like this:
IList list = GetSomeList();
MyEntity1 result = list.SingleOrDefault(
You can use the Select
operator:
IList list = GetSomeList();
MyEntity1 result = list
.Select(x => new { Item = x, Entity2 = GetMyEntity2(x) })
.SingleOrDefault(x => x.Entity2 != null && x.Entity2.Id != null && x.Entity2.Id > 0);
Or, since you're not even using the Item
after pushing it through GetMyEntity2
you could just have:
MyEntity1 result = list
.Select(x => GetMyEntity2(x))
.SingleOrDefault(x => x != null && x.Id != null && x.Id > 0);