Guest User

Untitled

a guest
Aug 15th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. class User
  2. {
  3. public virtual int id { get; set; }
  4. public virtual string name { get; set; }
  5.  
  6.  
  7. }
  8.  
  9. class MapUser : ClassMap<User>
  10. {
  11. public MapUser()
  12. {
  13. Id(x => x.id);
  14. Map(x => x.name);
  15. }
  16.  
  17. static void Main(string[] args)
  18. {
  19.  
  20. string connectionString = "Server=127.0.0.1; Port=5432; User Id=credit; Password=;Database=databir;";
  21.  
  22.  
  23.  
  24. try
  25. {
  26. ISessionFactory sessionFactory = Fluently.Configure().Database(PostgreSQLConfiguration.PostgreSQL81
  27. .ConnectionString(c => c.FromAppSetting(connectionString)).ShowSql()).Mappings(m => m.FluentMappings.AddFromAssembly(User)).BuildSessionFactory();
  28. var sefact = sessionFactory;
  29. using (var session = sefact.OpenSession())
  30. {
  31. using (var txt = session.BeginTransaction())
  32. {
  33. var use1 = new User
  34. {
  35. id = 1,
  36. name = "jakhongir"
  37. };
  38. session.Save(use1);
  39. }
  40. }
  41.  
  42.  
  43. }
  44. catch (Exception e)
  45. {
  46. Console.WriteLine(e);
  47. throw;
  48. }
  49.  
  50.  
  51. }
Add Comment
Please, Sign In to add comment