daily pastebin goal
74%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Marten;
  2. using Marten.Linq;
  3. using System;
  4. using System.Linq;
  5.  
  6. namespace DemoBugMarten
  7. {
  8.     class User
  9.     {
  10.         public Guid Id { get; set; }
  11.  
  12.         public string RealName { get; set; }
  13.  
  14.         public string DisplayName { get; set; }
  15.     }
  16.  
  17.     class MegaUser : User
  18.     {
  19.     }
  20.  
  21.     public class UserMartenRegistry : MartenRegistry
  22.     {
  23.         public UserMartenRegistry()
  24.         {
  25.             this.For<User>().AddSubClass<MegaUser>();
  26.         }
  27.     }
  28.  
  29.     class Program
  30.     {
  31.         static void Main(string[] args)
  32.         {
  33.             var megaUser1 = new MegaUser() { DisplayName = "Yann", RealName = "Yann Yann" };
  34.             var megaUser2 = new MegaUser() { DisplayName = "Robin", RealName = "Robin Robin" };
  35.             var megaUser3 = new MegaUser() { DisplayName = "Marten", RealName = "Marten Marten" };
  36.  
  37.             var cs = "Host=localhost;Port=5432;Database=demo;User ID=postgres;Password=password";
  38.             var store = DocumentStore.For(_ =>
  39.             {
  40.                 _.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate;
  41.                 _.Connection(cs);
  42.                 _.CreateDatabasesForTenants(c =>
  43.                     c.ForTenant()
  44.                     .CheckAgainstPgDatabase()
  45.                     .WithOwner("postgres")
  46.                     .WithEncoding("UTF-8")
  47.                     .ConnectionLimit(-1));
  48.                 _.Schema.Include<UserMartenRegistry>();
  49.             });
  50.  
  51.             var session = store.OpenSession();
  52.  
  53.             session.DeleteWhere<MegaUser>(_ => true);
  54.             session.Insert(megaUser1);
  55.             session.Insert(megaUser2);
  56.             session.Insert(megaUser3);
  57.  
  58.             session.SaveChanges();
  59.  
  60.                 var query = session.Query<MegaUser>()
  61.                     .Where(_ => _.DisplayName == "Yann" || _.DisplayName == "Robin");
  62.  
  63.             var cmd = query.ToCommand(FetchType.FetchMany);
  64.             Console.WriteLine(cmd.CommandText);
  65.  
  66.             var queryList = query.ToList();
  67.             foreach (var item in queryList)
  68.             {
  69.                 Console.WriteLine(item.DisplayName);
  70.             }
  71.             Console.ReadLine();
  72.         }
  73.     }
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top