我是 NHibernate 的新手。我可以使用 Fluent Hibernate 的模式来执行以下语句,例如如果表不存在则创建新表如果该表存在则使用 Fluent Nhibernate 插入到它的值中。namespace ConsoleApplication1{ public class Program { public string connectionString = "Server=127.0.0.1; Port=5432; User Id=credit; Password=123;Database=databir;"; public static ISessionFactory CreateSessionFactory() { ISessionFactory isessionFactory = Fluently.Configure() .Database(PostgreSQLConfiguration.PostgreSQL81 .ConnectionString("Server=127.0.0.1; Port=5432; User Id=credit; Password=123;Database=databir;")) .Mappings(m => m .FluentMappings.AddFromAssemblyOf<MapUser>()).ExposeConfiguration(c => {var schema = new SchemaExport(c); schemaExport.Execute(true,false,false);}) .BuildSessionFactory(); return isessionFactory; } static void Main(string[] args) { var staff = CreateSessionFactory(); using (ISession session = staff.OpenSession()) { using (var txt = session.BeginTransaction()) { user1 user = new user1 { name = "jakhongir" }; session.Save(user); txt.Commit(); } } } }}我无法插入到数据库中,它每次都在创建新表,以便在表不存在的情况下插入到表中,只需使用此值创建它
- 1 回答
- 0 关注
- 216 浏览
添加回答
举报
0/150
提交
取消