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 :
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();
}
}
精彩评论