NHibernateを使用する汎用リポジトリがあります。IDのタイプも汎用パラメータです。
/// <summary>
/// Represents a common base class for repositories.
/// </summary>
/// <typeparam name="TEntity"> The type of the entity. </typeparam>
/// <typeparam name="TId"> The type of the ID of the entity. </typeparam>
public abstract class RepositoryBase<TEntity, TId> : IRepository<TEntity, TId> where TEntity : EntityBase<TEntity, TId>
Contains
この場合、NHibernateで高速で読みやすい優れたジェネリックメソッドを実装するにはどうすればよいですか?
public bool Contains(TId id)
{
using (var session = NHibernateHelper.OpenSession())
{
// throws an excpetion that Equals is not supported
return session.QueryOver<TEntity>().Where(e => e.Id.Equals(id)).RowCount() > 0;
}
}
アップデート:
私の場合、NHibernateのlazyloadはオフになっています。