Something else, I wanted to abstract a join on my query away.
public static IQueryable<EP> Test<T, CP>(string entityType, IQueryable<CP> cplist, IQueryable<T> list) where T : IShivamEntity where CP : IContextPermission
{
var result = list.Join(cplist.Where(p=>(p.Permission & 1) == 1), p => p.Id, p => p.EntityId, (u, cp) => new EP { EntityId = u.Id, Permission = cp.Permission.GetValueOrDefault() });
return result;
}
This fails. If I write the exact same line with strong types it works fine. I believe this fails because the MemberInfo for Init expression (and the cplist where clause) are pointing to the interface members and not the entity members.
Would this work if the MemberInfos were swapped to the properties form the entity classes? Any hints on how I could do this...?
Forgetting the where clause for a moment, I have my member init defined lile this:
System.Linq.Expressions.Expression<Func<T, CP, EP>> test = (u, cp) => new EP { EntityId = u.Id, Permission = cp.Permission.GetValueOrDefault() };
Then:
var initExpr = (((System.Linq.Expressions.MemberInitExpression)test.Body);
Here's where I'm getting confused on how to remake the binding expression:
var idBinding = Expression.Bind(
((System.Linq.Expressions.MemberAssignment)initExpr.Bindings[0]).Member,
Expression.MakeMemberAccess()//think i need a new member access here pointing to the entity classes id property rather than the interfaces id property.
)
I'm using llbl 3.
If my initial query is in linq is there some way to tap into the provider to get the generated relation predicate bucket and add to it (mix linq with llbl query types). I ask this because obviously what I am trying to do doesn't lend itself well to llbl linq, however I still want to write my main queries in linq.