2

这是我在 mvc4 中的课程:

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);
    }
}

但有一些错误:

  • 找不到类型或命名空间名称“where”(您是否缺少 using 指令或程序集引用?)
  • 找不到类型或命名空间名称“T”(您是否缺少 using 指令或程序集引用?)

如何解决?谢谢。

4

1 回答 1

4

根据 where generic constraint 中的msdn 文档,您必须这样做:

public interface IGenericRepository<T> where T : class

在 IGenericRepository<T> 和 where 之间不能有 :。

于 2013-03-25T09:01:30.593 回答