流暢な nhibernate のリポジトリ モデルを実装しています。
私のプロジェクトは次の構造を持っています
public interface IRepository<T>
{
#region Create Methods 1
/// <summary>
/// This method Submits the Bonus Offer to the database.
/// </summary>
/// <param name="Value">Type of Bonus Subject Eg. Bonus1, Bonus2, Bonus3, Bonus4 </param>
void SubmitPost(T Value);
#endregion
#region Read Methods 4
/// <summary>
/// This method retrieves the Bonus offers not older than a month.
/// </summary>
/// <returns>Returns a List of Type T which is collection of particular type of Bonus Subject Eg. Bonus1, Bonus2, Bonus3, Bonus4</returns>
IList<T> GetPostsNotOlderThan30Days();
/// <summary>
/// This method returns the most recent 10 posts.
/// </summary>
/// <returns>Returns a List of Type T which contains a collection of Bonus offers which are the top 10 recently posted ones.</returns>
IList<T> GetRecent10Posts();
/// <summary>
/// This method returns a Bonus Subject given its matching Id Provided.
/// </summary>
/// <param name="Id">Id of the Bonus Subject of Type T. Eg. If of any of the Bonus1, Bonus2, Bonus3, Bonus4 Subjects.</param>
/// <returns></returns>
T GetPostById(object Id);
/// <summary>
/// This method returns all the Bonus offers of any Particular Bonus Subject posted by a particular user.
/// </summary>
/// <param name="UserId">Logged In UserId</param>
/// <returns></returns>
IList<T> GetUserPosts(object UserId);
#endregion
}
and I have 4 Bonus Types namely Bonus1, Bonus2, Bonus3, Bonus4 All these have some common properties like DateUpdated, DateExpires. And when I wanted to implement the class for IRepository which is BonusRepository
public class BonusRepository<T>:IRepository<T> where T:class
{
protected Configuration config;
protected ISessionFactory sessionFactory;
public BonusRepository(string conStr)
{
config=Fluently.Configure()
.Database(
MsSqlConfiguration
.MsSql2008
.ConnectionString(conStr))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<BonusRepository<T>>())
.BuildConfiguration();
sessionFactory = config.BuildSessionFactory();
}
#region Create Methods 1
/// <summary>
/// This method Submits the Bonus Offer to the database.
/// </summary>
/// <param name="value">Type of Bonus Subject Eg. Bonus1, Bonus2, Bonus3, Bonus4</param>
public void SubmitPost(T value)
{
using (var session = sessionFactory.OpenSession())
using (var transaction = session.BeginTransaction())
{
session.Save(value);
transaction.Commit();
}
}
#endregion
#region Read Methods 4
/// <summary>
/// This method retrieves the Bonus offers not older than a month.
/// </summary>
/// <returns>Returns a List of Type T which is collection of particular type of Bonus Subject Eg. Bonus1, Bonus2, Bonus3, Bonus4</returns>
public IList<T> GetPostsNotOlderThan30Days()
{
using (var session = sessionFactory.OpenSession())
using (var transaction = session.BeginTransaction())
{
//Here I'm unable to get DateUpated, DateExpires
IList<T> returnVal=session.QueryOver<T>()
.Where(c=>c.
}
}
}
以下のようなクラスもありますが、Bonus1Repository: BonusRepository, IRepository Bonus2Repository: BonusRepository, IRepository Bonus3Repository: BonusRepository, IRepository Bonus4Repository: BonusRepository, IRepository ですが、必要な機能はすべてのエンティティで同じであるため、BonusRepository クラス iteslf で実装したいと考えていました。これに最適なアプローチは何ですか? 誰でもこれに対する解決策を提案できますか?
前もって感謝します。