Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ISession session;
- Configuration config;
- ReferenceResolver res;
- void Main()
- {
- CreateSession();
- int[] test = { 1 };
- var q = from dh in Query<Process_DeliveryHead>()
- from wc in dh.WorkflowControls
- where dh.HeadId != 0 && wc.ReferenceType == WorkflowActivityReferenceType.DeliveryHead &&
- wc.WorkflowActivity.ActivityId == WorkflowActivityConstants.PickingActivityId &&
- wc.State < WorkflowState.Closed
- orderby dh.UnloadSequence descending
- select new { dh, wc };
- var h = 1;
- h.Dump(1);
- session.Transaction.Commit();
- }
- public IQueryable<T> Query<T>()
- {
- return session.Query<T>();
- }
- private T Get<T>(object id)
- {
- return session.Get<T>(id);
- }
- private T Load<T>(object id)
- {
- return session.Load<T>(id);
- }
- private void Save(object obj)
- {
- session.Save(obj);
- }
- private class LinqPadContext : GrellStorageContext
- {
- public Configuration GetNhConfiguration(IEnumerable<Type> mappingClasses, IEnumerable<Type> importedTypes)
- {
- var cfg = Fluently
- .Configure()
- .Database(
- MsSqlConfiguration
- .MsSql2008
- .Dialect<SqlServerDialect>()
- .ConnectionString(@"Data Source=localhost\MSSQLSERVER02;Initial Catalog=Grell_Logis-T;Integrated Security=True")
- .DefaultSchema("lo")
- .UseReflectionOptimizer()
- );
- cfg.Mappings(AddMappingClasses(mappingClasses));
- //cfg.Mappings(AddAutoMappingClasses(autoMappingClasses));
- cfg
- .Mappings(BuildDefaultNhMappingConvention())
- .ExposeConfiguration(BuildDefaultNhConfiguration(importedTypes, "300"))
- .Cache(BuildDefaultNhCache());
- return cfg.BuildConfiguration();
- }
- public Configuration GetConfiguration()
- {
- var mappingClasses = GetEntityMapNamespaces().Keys.SelectMany(ns => ExtractEntityModels(NFriends.Reflection.ReflectionUtility.GetAssembly(ns), StorageContextType.Standard)).ToList();
- //var autoMappingClasses = GetEntityMapNamespaces().Keys.SelectMany(ns => ExtractAutoMapModels(NFriends.Reflection.ReflectionUtility.GetAssembly(ns), StorageContextType.Standard)).ToList();
- //var autoMappingClasses = new Type[0];
- return GetNhConfiguration(mappingClasses, GetImportedTypes());
- }
- }
- // Define other methods and classes here
- public void CreateSession()
- {
- config = new LinqPadContext().GetConfiguration();
- Util.ClearResults();
- var sessionFactory = config.BuildSessionFactory();
- var x = new MultiInterceptors();
- session = sessionFactory.OpenSession(x);
- //x.AddInterceptors(new LoggingInterceptor(session));
- res = new ReferenceResolver(config, session);
- session.BeginTransaction();
- }
- public int GetNextRowId(string generator)
- {
- return Convert.ToInt32(session.CreateSQLQuery("SELECT NEXT VALUE FOR lo." + generator + "$").UniqueResult());
- }
- public class LoggingInterceptor : EmptyInterceptor, IInterceptor
- {
- bool _flushed;
- ISession _session;
- public LoggingInterceptor(ISession session)
- {
- _session = session;
- }
- SqlString IInterceptor.OnPrepareStatement(SqlString sql)
- {
- var textWriter = Util.SqlOutputWriter;
- textWriter.WriteLine(sql.ToString());
- return base.OnPrepareStatement(sql);
- }
- public override void PostFlush(ICollection entities)
- {
- return;
- if (_flushed)
- return;
- _flushed = true;
- "Flushed".Dump(1);
- _session.Flush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement