how to check if IQueryable<T>.ElementType is Iterface
我的(ef-db-first)类型位于接口
埃多克斯1〔3〕
完整方法如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | public static IQueryable<T> ApplySearch<T>(this IQueryable<T> queryable, SearchModel search) where T : class { if (search != null && search.PolicyNumber.HasValue && typeof(IPolicyNumber).IsAssignableFrom(typeof(T))) { queryable = queryable.SearchByPolicyNumber(search); } return queryable; } public static IQueryable<IPolicyNumber> SearchByPolicyNumber<IPolicyNumber>(this IQueryable<IPolicyNumber> queryable, SearchModel search) { var policyNumberParameterLambda = Expression.Parameter((typeof(IPolicyNumber))); var policyNumberColumnLambda = Expression.Property(policyNumberParameterLambda,"POLICY_NO"); var lambda = Expression.Lambda<Func<IPolicyNumber, bool>>( Expression.Equal(policyNumberColumnLambda, Expression.Convert(Expression.Constant(search.PolicyNumber), policyNumberColumnLambda.Type) ), policyNumberParameterLambda); return queryable.Where(lambda); } |
使用
江户十一〔一〕号