Linq Join with Dynamic Expression
问题 I'm attempting to do a dynamic join in linq. Meaning that I only know at runtime what field the join will occur on. I've done the following: var itemParam = Expression.Parameter(typeof(E), "obj"); var entityAccess = Expression.MakeMemberAccess(Expression.Parameter(typeof(E), "obj"), typeof(E).GetMember(Field).First()); var lambda = Expression.Lambda(entityAccess, itemParam); var q = dbSet.Join(context.Acl, lambda, acl => acl.ObjectID, (entity, acl) => new { Entity = entity, ACL = acl });