0
Windows FormsアプリケーションでNHibernateを使用していて、リポジトリクラスの接続文字列を変更する必要があります。私は、現在のセッションを取得しようとすると、しかし、私はこのエラーを取得する:WindowsアプリケーションのNhibernateセッション構成
No CurrentSessionContext configured
私のリポジトリクラスは以下の通りです:
public class UserRepository : Repository<User>, IUserRepository
{
public UserRepository(ISessionFactory planningUow) : base(planningUow)
{
planningUow.GetCurrentSession().Connection.ConnectionString = "test";
}
public IQueryable<User> GetByUserId(Guid id)
{
return Session.Query<User>().Where(bd => bd.UserId == id).AsQueryable();
}
public IQueryable<User> GetAllUsers()
{
return Session.Query<User>().AsQueryable();
}
public IQueryable<User> GetByUserPassword(string userName, string password)
{
return Session.Query<User>().Where(x => x.UserName == userName && x.Password == password).AsQueryable();
}
}
と私の流暢NHibernateの構成コードは以下の通りです:
public ISessionFactory CreateSessionFactory()
{
try
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(x => x.FromConnectionStringWithKey(ConnectionString)))
.Mappings(m =>
m.FluentMappings
.AddFromAssemblyOf<UserMap>())
.ExposeConfiguration(config => { new SchemaUpdate(config).Execute(false, true); })
.BuildSessionFactory();
}
catch (Exception ex)
{
throw ex;
}
}
現在のセッションを取得して接続文字列を取得するにはどうすればよいですか?