2012-04-13 97 views
0

我想在ef codefirst中添加一些条件(where)给linq。如何通过依赖注入将过滤器添加到EF

using (var context = new Context()) 
{ 
      var u= context.Users; 
      **u.where(my where condition)** 
     } 

是否有某种方式让我二叔到所有的选择, 如:BeforeSelected?

谢谢

回答

1

最简单的方法是创建一个包装在DbContext上。

public class EfWrapper:Context 
{ 
private DbContext _dbContext; 

    public EfWrapper(DbContext context){ 
    _dbContext=context; 
    } 

    public IEnumerable <User> Users{ 
    get 
    { 
     return _dbContext.Users.Where(my where condition); 
    } 
} 


} 
+0

谢谢,我试试看 – Raymond 2012-04-13 06:09:05

相关问题