NHibernate.Cfg.Configuration setCfg(NHibernate.Cfg.Configuration c) { //c.Properties.Add("hbm2ddl.keywords", "none"); c.Properties.Add("show_sql", "false"); c.Properties.Add("adonet.batch_size", "100"); c.Properties.Add("generate_statistics", "false"); c.Properties.Add("format_sql", "true"); c.Properties.Add("command_timeout", "60"); c.Properties.Add("current_session_context_class", "web"); return c; } string connectionString = "Server=.,8013;Database=db;Uid=sa;Pwd=mypwd;"; var assemblyName = Assembly.Load("ClassMapping"); var _sessionFactory = Fluently.Configure().Database(MsSqlConfiguration.MsSql2012.ConnectionString(connectionString) .Provider<NHibernate.Connection.DriverConnectionProvider>() .Driver<NHibernate.Driver.Sql2008ClientDriver>()) .Mappings(m => m.FluentMappings.AddFromAssembly(assemblyName).ExportTo("c:\\")) .ExposeConfiguration(c => setCfg(c)) .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, false)) .ExposeConfiguration(f => f.SetInterceptor(new SqlStatementInterceptor())) .BuildSessionFactory();
ClassMapping
namespace ClassMapping { #region AgentsMap public class AgentMap : ClassMapping<Agent> { public AgentMap() { SelectBeforeUpdate(true); DynamicUpdate(true); Id(p => p.AgentId, map => map.Generator(Generators.Native)); Version(p => p.Version, map => { }); Property(p => p.StateId); } } }
vs生成时不提示报错,但是在查询时,查询不到数据