当前位置:编程学习 > C#/ASP.NET >>

动态Include 问题


public List<T> FindListByExpression(Expression<Func<T, bool>> where, string greedyLoad = "")
        {
            try
            {
 
                using (context = new qqMarketingEntities1())
                {
                    var query = context.Set<T>();
                    if (!string.IsNullOrEmpty(greedyLoad))
                    {
                        List<string> greedyLoads = greedyLoad.Split(',').ToList();
                        /*foreach (var i in greedyLoads)
                        {
                            query.Include(i);
                        }
                        query.Where(where);*/无法查询,请问这里如何修改
                    }
 
                    List<T> result = query.ToList<T>();
                    return result;
                }
            }
            catch (Exception e)
            {
                throw e;
            }
 
        }
--------------------编程问答-------------------- 上下文?
报什么错? --------------------编程问答-------------------- 原来的写法不报错,只是找不到数据 --------------------编程问答--------------------

foreach (var i in greedyLoads){
    query = query.Include(i);
}
query = query.Where(where);
--------------------编程问答-------------------- 反射                     --------------------编程问答--------------------

public List<T> FindListByExpression(Func<T, bool> where, string greedyLoad = "")
--------------------编程问答--------------------
引用 3 楼 kittying 的回复:

foreach (var i in greedyLoads){
    query = query.Include(i);
}
query = query.Where(where);
补充:.NET技术 ,  LINQ
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,