2013-03-25 16 views
2

這是我的類mvc4:IGenericRepository <T>:其中T:classnot工作

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Linq.Expressions; 
using System.Web; 

namespace xxx.Areas.admin.Models 
{ 
    public interface IGenericRepository<T> : where T : class 
    { 
     IQueryable<T> AsQueryable(); 

     IEnumerable<T> GetAll(); 
     IEnumerable<T> Find(Expression<Func<T, bool>> predicate); 
     T Single(Expression<Func<T, bool>> predicate); 
     T SingleOrDefault(Expression<Func<T, bool>> predicate); 
     T First(Expression<Func<T, bool>> predicate); 
     T GetById(int id); 

     void Add(T entity); 
     void Delete(T entity); 
     void Attach(T entity); 
    } 
} 

但有是一些錯誤:

  • 類型或命名空間名稱 '其中' 不能找到(是否缺少using指令或程序集引用?)
  • 類型或命名空間名稱「T」找不到(是否缺少using指令或程序集引用?)

如何解決?謝謝。

+0

我的回答是否解決您的問題?如果確實如此,你能否接受答案? – 2013-04-08 11:56:39

回答

4

根據msdn documentation從你必須這樣做,這樣的地方一般約束:

public interface IGenericRepository<T> where T : class 

你絕不能有:在IGenericRepository < T>和地方之間。

+0

問題修復!謝謝。 – 2013-04-20 06:34:17