Hello.
{
static void Main(string[] args)
{
var factory = BuildFactory();
using (ISession session = factory.OpenSession())
{
using (ITransaction tx = session.BeginTransaction())
{
using (FileStream fi = File.OpenRead(@"C:\A\2013-10-31_1633.png"))
{
var photoBytes = new byte[fi.Length];
fi.Read(photoBytes, 0, photoBytes.Length);
var te = new TestEntity { Image = photoBytes };
session.SaveOrUpdate(te);
tx.Commit();
}
}
}
}
internal static Configuration GetConfiguration()
{
DomainMapper mapper = new DomainMapper();
HbmMapping generatedMappigs = mapper.GenerateMappigs();
var cfg = new Configuration();
cfg.SessionFactory().Proxy.Through<NHibernate.Bytecode.DefaultProxyFactoryFactory>().Integrate.Using<MsSql2008Dialect>()
.AutoQuoteKeywords().Connected.By<SqlClientDriver>().ByAppConfing("DBConnectionString").CreateCommands
.ConvertingExceptionsThrough<SQLStateConverter>();
cfg.SetProperty("show_sql", "true");
cfg.SetProperty("format_sql", "true");
cfg.AddDeserializedMapping(generatedMappigs, string.Empty);
new SchemaUpdate(cfg).Execute(true, true);
return cfg;
}
private static ISessionFactory BuildFactory()
{
Configuration cfg = GetConfiguration();
return cfg.BuildSessionFactory();
}
}