This is a fascinating class here. It is abstract, meaning that it cannot be instantiated. It is a base class for our repositories.
using System;
using Spring.Data.NHibernate.Support;
using System.Collections.Generic;
using System.Linq;
using NHibernate.Linq;
using App.Core.Entities;
using LinqSpecs;
using Spring.Transaction.Interceptor;
using System.ComponentModel.DataAnnotations;
namespace App.Data.Storage
{
public abstract class DataAccessObject<T, TId> : HibernateDaoSupport
where T : BaseEntity<TId>
{
public IQueryable<T> Page(IQueryable<T> query, int page, int pageSize)
{
return query.Page<T>(page, pageSize);
}
public IQueryable<T> FindAll(Specification<T> specification)
{
return GetQuery(specification);
}
public IQueryable<T> GetAll()
{
return Session.Query<T>();
}
public T GetById(TId id)
{
return Session.Get<T>(id);
}
public T Load(TId id)
{
return Session.Load<T>(id);
}
more core here...
Repositories inherit from DataAccessObject like so...
using System;
using App.Core.Entities;
using App.Core.Repositories;
namespace App.Data.Storage
{
public class FooRepository : DataAccessObject<Foo, Guid>, IFooRepository
{
}
}
No comments:
Post a Comment