我用谷歌搜索了它,但我找不到任何工作示例如何通过代码配置 nhibernate 3.3。这是我能找到的,但它不起作用,它抛出异常“用户必须提供 ADO.NET 连接”
var cfg = new Configuration();
cfg.DataBaseIntegration(c=> c.Dialect<MsSql2008Dialect>());
cfg.SetProperty("hibernate.connection.connection_string", "Data Source=localhost;Initial Catalog=Test;Integrated Security=SSPI;")
.SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver")
.SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
var mapper = new ConventionModelMapper();
mapper.Class<User>(map =>
{
map.Id(x => x.Id, m => m.Generator(Generators.Guid));
map.Property(x => x.UserName);
});
var mapping = mapper.CompileMappingFor(new Type[] { typeof(User) });
cfg.AddDeserializedMapping(mapping, "test");
var factory = cfg.BuildSessionFactory();
var session = factory.OpenSession();
session.SaveOrUpdate(new User() { Id = Guid.NewGuid(), UserName = "Hello" });
session.Flush();
session.Close();
factory.Close();
怎么了?什么不见了?我在哪里可以找到一个工作示例?
谢谢