I am trying to write a generic repository for my classes using
NHibernate. I have my only hbm.xml file marked as Embedded Resource.
In the following code, the GetAll() method works just fine, however
the Get(TIdentifier identifier) does not. For this method, I receive
the error message... No persister for:
ConfigurationManager.Interface.IPackageConfiguration.
This is my generic repository...
public class PackageConfigurationRepository<TIdentifier, TEntity>
where TEntity : class
{
public IList<TEntity> GetAll()
{
ISessionFactory sessionFactory = new
Configuration().Configure().BuildSessionFactory();
ISession session = sessionFactory.OpenSession();
ICriteria criteria = session.CreateCriteria<TEntity>();
IList<TEntity> query = criteria.List<TEntity>();
return query;
}
public TEntity Get(TIdentifier identifier)
{
ISessionFactory sessionFactory = new
Configuration().Configure().BuildSessionFactory();
ISession session = sessionFactory.OpenSession();
return session.Get<TEntity>(identifier); <=FAILS HERE WITH
ABOVE ERROR MSG
}
}
This is how I call the generic repository...
static public void GetById()
{
IPackageConfigurationIdentifier identifier = new
PackageConfigurationIdentifier();
identifier.ConfigurationFilter = "ID1";
identifier.PackagePath = "ID2";
NoGenericRepository noGenericRepository = new
NoGenericRepository();
IPackageConfiguration configuration =
noGenericRepository.Get(identifier);
PackageConfigurationRepository<IPackageConfigurationIdentifier,
IPackageConfiguration> repository =
new
PackageConfigurationRepository<IPackageConfigurationIdentifier,
IPackageConfiguration>();
configuration = repository.Get(identifier);
}
static public void GetAll() <= WORKS FINE
{
PackageConfigurationRepository<IPackageConfigurationIdentifier,
IPackageConfiguration> repository =
new
PackageConfigurationRepository<IPackageConfigurationIdentifier,
IPackageConfiguration>();
IList<IPackageConfiguration> configs =
repository.GetAll();
}
So how does it work for the GetAll() method, but fails for the
GetById() method?
Thanks,
Kyle
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.