Guest User

Untitled

a guest
Sep 20th, 2019
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. ```c#
  2. using System.Data;
  3. using ServiceStack.DataAnnotations;
  4. using ServiceStack.OrmLite;
  5.  
  6. namespace Test
  7. {
  8. class Program
  9. {
  10. public class Person
  11. {
  12. [AutoIncrement]
  13. public int Id { get; set; }
  14.  
  15. public string Name { get; set; }
  16. }
  17.  
  18. public static void Main(string[] _)
  19. {
  20. var factory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);
  21.  
  22. using (var db = factory.OpenDbConnection())
  23. {
  24. db.CreateTable<Person>();
  25.  
  26. var person = new Person { Name = "Paul" };
  27. var personId = db.Insert(person); // Id is also auto set.
  28.  
  29. using (var trans = db.OpenTransaction(IsolationLevel.ReadCommitted))
  30. {
  31. person = db.Single(db.From<Person>().Where(x => x.Name == "Paul"));
  32. person = db.SingleById<Person>(personId);
  33.  
  34. person.Name = "Another name";
  35.  
  36. db.Save(person);
  37.  
  38. trans.Commit();
  39. }
  40. }
  41. }
  42. }
  43. }
  44. ```
Advertisement
Add Comment
Please, Sign In to add comment