I\'m developing a multi-tenant web app (stack: MVC 4 + Entity framework 4.3). My requirements are pretty simple: each tenant has the same UI and CodeBase.
In my databa
You can do the reflection check and then manually create an expression tree that EF can understand.
For example:
int tenantId = 5;
var tenantIdInfo = typeof(TEntity).GetProperty("TenantId");
if (tenantIdInfo != null)
{
var entity = Expression.Parameter(typeof(TEntity), "it");
var predicate = (Expression<Func<TEntity, bool>>)Expression.Lambda(
Expression.Equal(
Expression.MakeMemberAccess(entity, tenantIdInfo),
Expression.Constant(tenantId, typeof(int))),
entity);
query = query.Where(predicate);
}