Advertisement
Guest User

Untitled

a guest
Aug 19th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Marten;
  4. using Marten.Linq;
  5.  
  6. namespace Sample
  7. {
  8. internal class Program
  9. {
  10. private static void Main(string[] args)
  11. {
  12. var store = DocumentStore.For(_ =>
  13. {
  14. _.Connection("host=localhost;database=sample;password=root;username=postgres");
  15. _.AutoCreateSchemaObjects = AutoCreate.All;
  16. });
  17.  
  18. using (var session = store.OpenSession())
  19. {
  20. var order = new Order {Customer = "Luca"};
  21. var line = new OrderLine() {Name = "Sample"};
  22. order.Lines.Add(line);
  23. session.Store(order);
  24. session.SaveChanges();
  25. }
  26.  
  27. using (var session = store.QuerySession())
  28. {
  29. QueryStatistics stats;
  30. session.Query<Order>().Stats(out stats);
  31. Console.WriteLine($"Count({stats.TotalResults})");
  32. }
  33. }
  34. }
  35.  
  36. public class Order
  37. {
  38. public int Id { get; set; }
  39. public string Customer { get; set; }
  40. public List<OrderLine> Lines { get; set; } = new List<OrderLine>();
  41. }
  42.  
  43. public class OrderLine
  44. {
  45. public string Name { get; set; }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement