零度空间

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

当需要把context的where条件作为参数的时候,

 

/// <summary>
        
/// 这样的where不能正常作为检索条件,执行后不会报错,但条件不会被使用,并且还会使后续添加的条件也无效。
        
/// </summary>
        
/// <param name="where"></param>
        public void AttachWhere(Func<AuthorRole, bool> w)
        {
            
using (DealerAuthorityDataContext dataContext = new DealerAuthorityDataContext())
            {
                var result 
= dataContext.AuthorRole.Where(w);
            }
        }

        
/// <summary>
        
/// 这样的where才能正常作为检索条件
        
/// </summary>
        
/// <param name="where"></param>
        public void AttachWhere(Expression<Func<AuthorRole, bool>> w)
        {
            
using (DealerAuthorityDataContext dataContext = new DealerAuthorityDataContext())
            {
                var result 
= dataContext.AuthorRole.Where(w);
            }
        }

 

posted on 2011-05-05 18:12  Diago  阅读(99)  评论(0编辑  收藏  举报