Ejemplo n.º 1
0
 public FakeRelationalDataStore(
     StateManager stateManager,
     DbContextService <IModel> model,
     EntityKeyFactorySource entityKeyFactorySource,
     EntityMaterializerSource entityMaterializerSource,
     ClrCollectionAccessorSource collectionAccessorSource,
     ClrPropertySetterSource propertySetterSource,
     RelationalConnection connection,
     CommandBatchPreparer batchPreparer,
     BatchExecutor batchExecutor,
     DbContextService <IDbContextOptions> options,
     ILoggerFactory loggerFactory)
     : base(stateManager, model, entityKeyFactorySource, entityMaterializerSource,
            collectionAccessorSource, propertySetterSource, connection, batchPreparer, batchExecutor, options, loggerFactory)
 {
 }
        public void Can_create_materializer_for_entity_with_fields()
        {
            var entityType = new Model().AddEntityType(typeof(SomeEntityWithFields));

            entityType.GetOrAddProperty("Id", typeof(int));
            entityType.GetOrAddProperty("Foo", typeof(string));
            entityType.GetOrAddProperty("Goo", typeof(Guid?));

            var factory = new EntityMaterializerSource(new MemberMapper(new FieldMatcher())).GetMaterializer(entityType);

            var gu     = Guid.NewGuid();
            var entity = (SomeEntityWithFields)factory(new ObjectArrayValueReader(new object[] { "Fu", gu, 77 }));

            Assert.Equal(77, entity.Id);
            Assert.Equal("Fu", entity.Foo);
            Assert.Equal(gu, entity.Goo);
        }
Ejemplo n.º 3
0
 public SqlServerQueryCompilationContext(
     [NotNull] IModel model,
     [NotNull] ILogger logger,
     [NotNull] ILinqOperatorProvider linqOperatorProvider,
     [NotNull] IResultOperatorHandler resultOperatorHandler,
     [NotNull] EntityMaterializerSource entityMaterializerSource,
     [NotNull] IQueryMethodProvider queryMethodProvider,
     [NotNull] IMethodCallTranslator methodCallTranslator)
     : base(
         Check.NotNull(model, "model"),
         Check.NotNull(logger, "logger"),
         Check.NotNull(linqOperatorProvider, "linqOperatorProvider"),
         Check.NotNull(resultOperatorHandler, "resultOperatorHandler"),
         Check.NotNull(entityMaterializerSource, "entityMaterializerSource"),
         Check.NotNull(queryMethodProvider, "queryMethodProvider"),
         Check.NotNull(methodCallTranslator, "methodCallTranslator"))
 {
 }
Ejemplo n.º 4
0
        private CommandBuilder setupCommandBuilder(DbContext context)
        {
            EntityMaterializerSource source = new EntityMaterializerSource(new MemberMapper(new FieldMatcher()));

            var loggerFactory = new LoggerFactory();

            var selectExpression        = new SelectExpression();
            var queryCompilationContext = new RelationalQueryCompilationContext(
                context.Model,
                loggerFactory.Create("new"),
                new LinqOperatorProvider(),
                new RelationalResultOperatorHandler(),
                source,
                new AsyncQueryMethodProvider(),
                new CompositeMethodCallTranslator());

            return(new CommandBuilder(selectExpression, queryCompilationContext));
        }
Ejemplo n.º 5
0
        public QueryBuffer(
            [NotNull] StateManager stateManager,
            [NotNull] EntityKeyFactorySource entityKeyFactorySource,
            [NotNull] EntityMaterializerSource materializerSource,
            [NotNull] ClrCollectionAccessorSource clrCollectionAccessorSource,
            [NotNull] ClrPropertySetterSource clrPropertySetterSource)
        {
            Check.NotNull(stateManager, "stateManager");
            Check.NotNull(entityKeyFactorySource, "entityKeyFactorySource");
            Check.NotNull(materializerSource, "materializerSource");
            Check.NotNull(clrCollectionAccessorSource, "clrCollectionAccessorSource");
            Check.NotNull(clrPropertySetterSource, "clrPropertySetterSource");

            _stateManager                = stateManager;
            _entityKeyFactorySource      = entityKeyFactorySource;
            _materializerSource          = materializerSource;
            _clrCollectionAccessorSource = clrCollectionAccessorSource;
            _clrPropertySetterSource     = clrPropertySetterSource;
        }
        public InMemoryQueryCompilationContext(
            [NotNull] IModel model,
            [NotNull] ILogger logger,
            [NotNull] EntityMaterializerSource entityMaterializerSource,
            [NotNull] EntityKeyFactorySource entityKeyFactorySource,
            [NotNull] InMemoryDatabase database)
            : base(
                Check.NotNull(model, "model"),
                Check.NotNull(logger, "logger"),
                new LinqOperatorProvider(),
                new ResultOperatorHandler(),
                Check.NotNull(entityMaterializerSource, "entityMaterializerSource"))
        {
            Check.NotNull(entityKeyFactorySource, "entityKeyFactorySource");
            Check.NotNull(database, "database");

            _entityKeyFactorySource = entityKeyFactorySource;
            _database = database;
        }
Ejemplo n.º 7
0
        protected QueryCompilationContext(
            [NotNull] IModel model,
            [NotNull] ILogger logger,
            [NotNull] ILinqOperatorProvider linqOperatorProvider,
            [NotNull] IResultOperatorHandler resultOperatorHandler,
            [NotNull] EntityMaterializerSource entityMaterializerSource)
        {
            Check.NotNull(model, "model");
            Check.NotNull(logger, "logger");
            Check.NotNull(linqOperatorProvider, "linqOperatorProvider");
            Check.NotNull(resultOperatorHandler, "resultOperatorHandler");
            Check.NotNull(entityMaterializerSource, "entityMaterializerSource");

            Model  = model;
            Logger = logger;
            LinqOperatorProvider     = linqOperatorProvider;
            ResultOperatorHandler    = resultOperatorHandler;
            EntityMaterializerSource = entityMaterializerSource;
        }
        public void Can_create_materializer_for_entity_ignoring_shadow_fields()
        {
            var entityType = new EntityType(typeof(SomeEntity));

            entityType.AddProperty("Id", typeof(int));
            entityType.AddProperty("IdShadow", typeof(int), shadowProperty: true, concurrencyToken: false);
            entityType.AddProperty("Foo", typeof(string));
            entityType.AddProperty("FooShadow", typeof(string), shadowProperty: true, concurrencyToken: false);
            entityType.AddProperty("Goo", typeof(Guid));
            entityType.AddProperty("GooShadow", typeof(Guid), shadowProperty: true, concurrencyToken: false);

            var factory = new EntityMaterializerSource(new MemberMapper(new FieldMatcher())).GetMaterializer(entityType);

            var gu     = Guid.NewGuid();
            var entity = (SomeEntity)factory(new ObjectArrayValueReader(new object[] { "Fu", "FuS", gu, Guid.NewGuid(), 77, 777 }));

            Assert.Equal(77, entity.Id);
            Assert.Equal("Fu", entity.Foo);
            Assert.Equal(gu, entity.Goo);
        }
Ejemplo n.º 9
0
        protected RelationalDataStore(
            [NotNull] StateManager stateManager,
            [NotNull] DbContextService <IModel> model,
            [NotNull] EntityKeyFactorySource entityKeyFactorySource,
            [NotNull] EntityMaterializerSource entityMaterializerSource,
            [NotNull] ClrCollectionAccessorSource collectionAccessorSource,
            [NotNull] ClrPropertySetterSource propertySetterSource,
            [NotNull] RelationalConnection connection,
            [NotNull] CommandBatchPreparer batchPreparer,
            [NotNull] BatchExecutor batchExecutor,
            [NotNull] ILoggerFactory loggerFactory)
            : base(stateManager, model, entityKeyFactorySource, entityMaterializerSource,
                   collectionAccessorSource, propertySetterSource, loggerFactory)
        {
            Check.NotNull(connection, "connection");
            Check.NotNull(batchPreparer, "batchPreparer");
            Check.NotNull(batchExecutor, "batchExecutor");

            _batchPreparer = batchPreparer;
            _batchExecutor = batchExecutor;
            _connection    = connection;
        }
Ejemplo n.º 10
0
        public static EntityServicesBuilder UseEntityMaterializerSource([NotNull] this EntityServicesBuilder builder, [NotNull] EntityMaterializerSource source)
        {
            Check.NotNull(source, "source");

            builder.ServiceCollection.AddInstance(source);

            return(builder);
        }
        private CommandBuilder setupCommandBuilder(DbContext context)
        {
            var source = new EntityMaterializerSource(new MemberMapper(new FieldMatcher()));

            var loggerFactory = new LoggerFactory();

            var selectExpression = new SelectExpression();
            var queryCompilationContext = new RelationalQueryCompilationContext(
                context.Model,
                loggerFactory.CreateLogger("new"),
                new LinqOperatorProvider(),
                new RelationalResultOperatorHandler(),
                source,
                new EntityKeyFactorySource(new BoxedValueReaderSource()),
                new AsyncQueryMethodProvider(),
                new CompositeMethodCallTranslator());

            return new CommandBuilder(selectExpression, queryCompilationContext);
        }