.net 泛型运用

DAL层

private DbContext MyContext;
        public BaseRepository(DbContext context)
        {
            MyContext = context;
        }

public IQueryable<S> GetAllGroups<S>(Expression<Func<T, bool>> predicate, Expression<Func<T, S>> selectLambda)
        {
            var query = MyContext.Set<T>().Where(predicate).AsQueryable();

            return query.Select(selectLambda);
        }

运用

List<Guid> lstguid=cis.GetAllGroups<Guid>(a => a.GroupID != null, a => a.GroupID).ToList();
原文地址:https://www.cnblogs.com/King-JJ/p/4940143.html