开发者

NHibernate repository not compile

开发者 https://www.devze.com 2023-03-26 00:57 出处:网络
I don\'t understand why the code below not compile (on the QueryOver line), I tried wih NHibernate 3.1 and3.2

I don't understand why the code below not compile (on the QueryOver line), I tried wih NHibernate 3.1 and 3.2

public interface IRepository<T> where T : class
{
    IQueryable<T> FindAll<T>();
    void Save(T obj);
}

public class RepositoryBase<T> : IRepository<T> where T : class
{
    protected ISession _sess开发者_Python百科ion = null;

    public RepositoryBase(ISession session)
    {
        _session = session;
    }

    public void Save(T obj)
    {
        _session.Save(obj);
    }

    public IQueryable<T> FindAll<T>()
    {
-        return _session.QueryOver<T>().List<T>().AsQueryable();
    }
}

Error :

NHibernate repository not compile


You do not need <T> in FindAll declarations because they already declared at the class level. You may also be missing some using statements. And there is a dash ( - ) in the QueryOver line. Following should compile in .NET 3.5 project:

using System.Linq;
using NHibernate;

public interface IRepository<T> where T : class {
    IQueryable<T> FindAll();
    void Save(T obj);
}

public class RepositoryBase<T> : IRepository<T> where T : class {
    protected ISession _session = null;

    public RepositoryBase(ISession session) {
        _session = session;
    }

    public void Save(T obj) {
        _session.Save(obj);
    }

    public IQueryable<T> FindAll() {
        return _session.QueryOver<T>().List<T>().AsQueryable();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消