Esempio n. 1
0
        public AbstraXProviderDbSet(AbstraXProviderDataProvider provider, AbstraXProviderDataContext abstraXProviderContext, string setName)
        {
            this.provider = provider;
            this.abstraXProviderContext = abstraXProviderContext;
            this.setName = setName;
            this.query   = new AbstraXProviderQuery();

            expression = Expression.Constant(this);
        }
        public IDbContextServices Initialize(IServiceProvider scopedProvider, IDbContextOptions contextOptions, DbContext context)
        {
            this.serviceProvider = scopedProvider;
            this.contextOptions  = contextOptions;
            this.providerContext = (AbstraXProviderDataContext)context;

            IInternalEntityEntryNotifier internalEntityEntryNotifier = scopedProvider.GetService <IInternalEntityEntryNotifier>();

            return(this);
        }
        public void InitializeSets(DbContext context)
        {
            var contextType = context.GetType();
            var properties  = contextType.GetProperties().Where(p => p.PropertyType.Name == typeof(DbSet <>).Name);

            this.providerContext = (AbstraXProviderDataContext)context;

            foreach (var property in properties)
            {
                var genericType = property.PropertyType.GenericTypeArguments.Single();
                var abstraXProviderDbSetType        = typeof(AbstraXProviderDbSet <>);
                var abstraXProviderDbSetGenericType = abstraXProviderDbSetType.MakeGenericType(genericType);
                var abstraXProviderDbSetConstructor = abstraXProviderDbSetGenericType.GetConstructor(new Type[] { typeof(AbstraXProviderDataProvider), typeof(AbstraXProviderDataContext), typeof(string) });
                var abstraXProviderDbSet            = abstraXProviderDbSetConstructor.Invoke(new object[] { this, context, property.Name });
                var dbSetProperty = new DbSetProperty(property.Name, genericType, this, false);

                dbSets.Add(dbSetProperty);

                property.SetValue(context, abstraXProviderDbSet);
            }
        }