2012-04-13 81 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

相關問題