private static EntityDescriptor GetDescriptor(
     DbContext context,
     IApplyQueryableConfiguration <TReadModel> queryableConfiguration)
 {
     return(Descriptors.GetOrAdd(context.Database.ProviderName, s =>
                                 new EntityDescriptor(context, queryableConfiguration)));
 }
Exemple #2
0
 internal IncludeExpression(
     IApplyQueryableConfiguration <TReadModel> source,
     Expression <Func <TReadModel, TProperty> > navigationPropertyPath)
 {
     _source = source;
     _navigationPropertyPath = navigationPropertyPath;
 }
Exemple #3
0
 internal IncludeString(
     IApplyQueryableConfiguration <TReadModel> source,
     string navigationPropertyPath)
 {
     _source = source;
     _navigationPropertyPath = navigationPropertyPath;
 }
            public EntityDescriptor(
                DbContext context,
                IApplyQueryableConfiguration <TReadModel> queryableConfiguration)
            {
                var entityType = context.Model.FindEntityType(typeof(TReadModel));

                _key                 = GetKeyProperty(entityType);
                _version             = GetVersionProperty(entityType);
                _queryByIdTracking   = CompileQueryById(queryableConfiguration, true);
                _queryByIdNoTracking = CompileQueryById(queryableConfiguration, false);
            }
        Include <TReadModel, TProperty>(
            this IApplyQueryableConfiguration <TReadModel> source,
            Expression <Func <TReadModel, TProperty> > navigationPropertyPath)
            where TReadModel : class, IReadModel, new()
        {
            if (navigationPropertyPath == null)
            {
                throw new ArgumentNullException(nameof(navigationPropertyPath));
            }

            return(new IncludeExpression <TReadModel, TProperty>(
                       source,
                       navigationPropertyPath));
        }
 public EntityFrameworkReadModelStore(
     IBulkOperationConfiguration bulkOperationConfiguration,
     ILog log,
     IReadModelFactory <TReadModel> readModelFactory,
     IApplyQueryableConfiguration <TReadModel> queryableConfiguration,
     IDbContextProvider <TDbContext> contextProvider,
     ITransientFaultHandler <IOptimisticConcurrencyRetryStrategy> transientFaultHandler)
     : base(log)
 {
     _readModelFactory       = readModelFactory;
     _queryableConfiguration = queryableConfiguration;
     _contextProvider        = contextProvider;
     _transientFaultHandler  = transientFaultHandler;
     _deletionBatchSize      = bulkOperationConfiguration.DeletionBatchSize;
 }
 private Func <DbContext, CancellationToken, string, Task <TReadModel> > CompileQueryById(
     IApplyQueryableConfiguration <TReadModel> queryableConfiguration,
     bool tracking)
 {
     return(tracking
         ? EF.CompileAsyncQuery((DbContext dbContext, CancellationToken t, string id) =>
                                queryableConfiguration.Apply(dbContext
                                                             .Set <TReadModel>()
                                                             .AsTracking())
                                .SingleOrDefault(e => EF.Property <string>(e, Key) == id))
         : EF.CompileAsyncQuery((DbContext dbContext, CancellationToken t, string id) =>
                                queryableConfiguration.Apply(
                                    dbContext
                                    .Set <TReadModel>()
                                    .AsNoTracking())
                                .SingleOrDefault(e => EF.Property <string>(e, Key) == id)));
 }
        Include <TReadModel>(
            this IApplyQueryableConfiguration <TReadModel> source,
            string navigationPropertyPath)
            where TReadModel : class, IReadModel, new()
        {
            if (navigationPropertyPath == null)
            {
                throw new ArgumentNullException(nameof(navigationPropertyPath));
            }

            if (string.IsNullOrWhiteSpace(navigationPropertyPath))
            {
                throw new ArgumentException("Must not be null or empty", nameof(navigationPropertyPath));
            }

            return(new IncludeString <TReadModel>(
                       source,
                       navigationPropertyPath));
        }