Пример #1
0
        // Constructors

        internal Session(Domain domain, SessionConfiguration configuration, bool activate)
            : base(domain)
        {
            Guid = Guid.NewGuid();
            IsDebugEventLoggingEnabled = OrmLog.IsLogged(LogLevel.Debug); // Just to cache this value

            // Both Domain and Configuration are valid references here;
            // Configuration is already locked
            Configuration  = configuration;
            Name           = configuration.Name;
            identifier     = Interlocked.Increment(ref lastUsedIdentifier);
            CommandTimeout = configuration.DefaultCommandTimeout;
            allowSwitching = configuration.Supports(SessionOptions.AllowSwitching);

            // Handlers
            Handlers = domain.Handlers;
            Handler  = CreateSessionHandler();

            // Caches, registry
            EntityStateCache               = CreateSessionCache(configuration);
            EntityChangeRegistry           = new EntityChangeRegistry(this);
            EntitySetChangeRegistry        = new EntitySetChangeRegistry(this);
            ReferenceFieldsChangesRegistry = new ReferenceFieldsChangesRegistry(this);
            entitySetsWithInvalidState     = new HashSet <EntitySetBase>();

            // Events
            EntityEvents = new EntityEventBroker();
            Events       = new SessionEventAccessor(this, false);
            SystemEvents = new SessionEventAccessor(this, true);

            // Etc.
            PairSyncManager                 = new SyncManager(this);
            RemovalProcessor                = new RemovalProcessor(this);
            pinner                          = new Pinner(this);
            Operations                      = new OperationRegistry(this);
            NonPairedReferencesRegistry     = new NonPairedReferenceChangesRegistry(this);
            CommandProcessorContextProvider = new CommandProcessorContextProvider(this);

            // Validation context
            ValidationContext = Configuration.Supports(SessionOptions.ValidateEntities)
        ? (ValidationContext) new RealValidationContext()
        : new VoidValidationContext();

            // Creating Services
            Services = CreateServices();

            disposableSet = new DisposableSet();
            remapper      = new KeyRemapper(this);

            disableAutoSaveChanges = !configuration.Supports(SessionOptions.AutoSaveChanges);

            // Perform activation
            if (activate)
            {
                ActivateInternally();
            }

            // Query endpoint
            SystemQuery = Query = new QueryEndpoint(new QueryProvider(this));
        }
Пример #2
0
        private static IQueryable <TItem> GetItemsQuery(QueryEndpoint qe, FieldInfo field)
        {
            var owner = Expression.Property(Expression.Constant(ownerParameter), ownerParameter.GetType()
                                            .GetProperty("Value", typeof(Entity)));
            var queryExpression = QueryHelper.CreateEntitySetQuery(owner, field);

            return(qe.Provider.CreateQuery <TItem>(queryExpression));
        }
Пример #3
0
 internal QueryEndpoint(QueryEndpoint outerEndpoint, IQueryRootBuilder queryRootBuilder)
 {
     ArgumentValidator.EnsureArgumentNotNull(outerEndpoint, "outerEndpoint");
     ArgumentValidator.EnsureArgumentNotNull(queryRootBuilder, "queryRootBuilder");
     Provider    = outerEndpoint.Provider;
     session     = outerEndpoint.session;
     RootBuilder = queryRootBuilder;
 }
Пример #4
0
        /// <summary>
        /// Overrides current query root builder (i.e. builder of <see cref="QueryEndpoint.All{T}"/> expression).
        /// After this method is called <see cref="Query"/> is changed to a new <see cref="QueryEndpoint"/>
        /// that utilizes specified <paramref name="queryRootBuilder"/>.
        /// </summary>
        /// <param name="queryRootBuilder"><see cref="IQueryRootBuilder"/> to use.</param>
        /// <returns><see cref="IDisposable"/> implementor
        /// that reverts <see cref="IQueryRootBuilder"/> to original
        /// once <see cref="IDisposable.Dispose"/> is called.</returns>
        public IDisposable OverrideQueryRoot(IQueryRootBuilder queryRootBuilder)
        {
            ArgumentValidator.EnsureArgumentNotNull(queryRootBuilder, "queryRootBuilder");
            var oldQuery = Query;
            var newQuery = new QueryEndpoint(oldQuery, queryRootBuilder);

            Query = newQuery;
            return(new Disposable(_ => Query = oldQuery));
        }