Advertisement
Guest User

12345

a guest
Oct 14th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. ISession session;
  2. Configuration config;
  3. ReferenceResolver res;
  4.  
  5.  
  6.  
  7.  
  8. void Main()
  9. {
  10.  
  11.  
  12.  
  13.  
  14. CreateSession();
  15. int[] test = { 1 };
  16. var q = from dh in Query<Process_DeliveryHead>()
  17. from wc in dh.WorkflowControls
  18. where dh.HeadId != 0 && wc.ReferenceType == WorkflowActivityReferenceType.DeliveryHead &&
  19. wc.WorkflowActivity.ActivityId == WorkflowActivityConstants.PickingActivityId &&
  20. wc.State < WorkflowState.Closed
  21. orderby dh.UnloadSequence descending
  22. select new { dh, wc };
  23.  
  24.  
  25.  
  26. var h = 1;
  27.  
  28.  
  29.  
  30. h.Dump(1);
  31.  
  32.  
  33.  
  34. session.Transaction.Commit();
  35.  
  36.  
  37.  
  38. }
  39.  
  40.  
  41.  
  42.  
  43. public IQueryable<T> Query<T>()
  44. {
  45. return session.Query<T>();
  46. }
  47.  
  48.  
  49.  
  50. private T Get<T>(object id)
  51. {
  52. return session.Get<T>(id);
  53. }
  54.  
  55.  
  56.  
  57. private T Load<T>(object id)
  58. {
  59. return session.Load<T>(id);
  60. }
  61.  
  62.  
  63.  
  64. private void Save(object obj)
  65. {
  66. session.Save(obj);
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73. private class LinqPadContext : GrellStorageContext
  74. {
  75. public Configuration GetNhConfiguration(IEnumerable<Type> mappingClasses, IEnumerable<Type> importedTypes)
  76. {
  77. var cfg = Fluently
  78. .Configure()
  79. .Database(
  80. MsSqlConfiguration
  81. .MsSql2008
  82. .Dialect<SqlServerDialect>()
  83. .ConnectionString(@"Data Source=localhost\MSSQLSERVER02;Initial Catalog=Grell_Logis-T;Integrated Security=True")
  84. .DefaultSchema("lo")
  85. .UseReflectionOptimizer()
  86. );
  87.  
  88.  
  89.  
  90.  
  91. cfg.Mappings(AddMappingClasses(mappingClasses));
  92. //cfg.Mappings(AddAutoMappingClasses(autoMappingClasses));
  93. cfg
  94. .Mappings(BuildDefaultNhMappingConvention())
  95. .ExposeConfiguration(BuildDefaultNhConfiguration(importedTypes, "300"))
  96. .Cache(BuildDefaultNhCache());
  97.  
  98.  
  99.  
  100. return cfg.BuildConfiguration();
  101. }
  102.  
  103.  
  104.  
  105. public Configuration GetConfiguration()
  106. {
  107. var mappingClasses = GetEntityMapNamespaces().Keys.SelectMany(ns => ExtractEntityModels(NFriends.Reflection.ReflectionUtility.GetAssembly(ns), StorageContextType.Standard)).ToList();
  108. //var autoMappingClasses = GetEntityMapNamespaces().Keys.SelectMany(ns => ExtractAutoMapModels(NFriends.Reflection.ReflectionUtility.GetAssembly(ns), StorageContextType.Standard)).ToList();
  109. //var autoMappingClasses = new Type[0];
  110. return GetNhConfiguration(mappingClasses, GetImportedTypes());
  111. }
  112. }
  113.  
  114.  
  115.  
  116. // Define other methods and classes here
  117. public void CreateSession()
  118. {
  119.  
  120.  
  121.  
  122. config = new LinqPadContext().GetConfiguration();
  123. Util.ClearResults();
  124.  
  125.  
  126.  
  127. var sessionFactory = config.BuildSessionFactory();
  128. var x = new MultiInterceptors();
  129.  
  130.  
  131.  
  132. session = sessionFactory.OpenSession(x);
  133. //x.AddInterceptors(new LoggingInterceptor(session));
  134. res = new ReferenceResolver(config, session);
  135. session.BeginTransaction();
  136. }
  137.  
  138.  
  139.  
  140.  
  141. public int GetNextRowId(string generator)
  142. {
  143. return Convert.ToInt32(session.CreateSQLQuery("SELECT NEXT VALUE FOR lo." + generator + "$").UniqueResult());
  144. }
  145.  
  146.  
  147.  
  148. public class LoggingInterceptor : EmptyInterceptor, IInterceptor
  149. {
  150. bool _flushed;
  151. ISession _session;
  152. public LoggingInterceptor(ISession session)
  153. {
  154. _session = session;
  155. }
  156.  
  157.  
  158.  
  159. SqlString IInterceptor.OnPrepareStatement(SqlString sql)
  160. {
  161. var textWriter = Util.SqlOutputWriter;
  162. textWriter.WriteLine(sql.ToString());
  163. return base.OnPrepareStatement(sql);
  164. }
  165.  
  166.  
  167.  
  168. public override void PostFlush(ICollection entities)
  169. {
  170. return;
  171. if (_flushed)
  172. return;
  173. _flushed = true;
  174. "Flushed".Dump(1);
  175. _session.Flush();
  176. }
  177.  
  178.  
  179.  
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement