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

ジェネリック制約の場所からのmsdnドキュメントによると、次のようにする必要があります。

public interface IGenericRepository<T> where T : class

IGenericRepository <T>とwhereの間に:を含めることはできません。

于 2013-03-25T09:01:30.593 に答える