示例#1
0
 protected override void OnConfiguring(EntityContextOptionsBuilder builder)
 {
     //builder.Options.CacheParsing = false;
     builder.Options.CacheExecution = true;
     //builder.UseMongoDB("server=mongodb://localhost;database=test");
     base.OnConfiguring(builder);
 }
示例#2
0
        /// <summary>
        /// 从现有的 <see cref="IServiceCollection"/> 里添加 <see cref="EntityContext"/> 对象。
        /// </summary>
        /// <param name="setupAction"></param>
        /// <returns></returns>
        public static EntityContextOptionsBuilder AddEntityContext(this IServiceCollection services, Action <EntityContextOptions> setupAction = null)
        {
            var options = new EntityContextOptions();

            setupAction?.Invoke(options);

            var builder = new EntityContextOptionsBuilder(options);

            if (services is ServiceCollection coll)
            {
                var desc = coll.FirstOrDefault(s => typeof(EntityContext).IsAssignableFrom(s.ServiceType));
                if (desc != null)
                {
                    services.Remove(desc);

                    if (setupAction != null)
                    {
                        services.Configure(setupAction);
                    }

                    services.AddScoped(desc.ServiceType);
                    services.AddScoped(s => options);

                    return(builder);
                }
            }

            return(builder);
        }
        private static EntityContextOptions ContextOptionsFactory <TContext>(IServiceProvider serviceProvider, Action <EntityContextOptionsBuilder> setupAction) where TContext : EntityContext
        {
            var builder = new EntityContextOptionsBuilder(typeof(TContext), new EntityContextOptions <TContext>(serviceProvider));

            setupAction?.Invoke(builder);
            return(builder.Options);
        }
        private static EntityContextOptions ContextOptionsFactory(Type contextType, Type optionsType, IServiceProvider serviceProvider, Action <EntityContextOptionsBuilder> setupAction)
        {
            var builder = new EntityContextOptionsBuilder(contextType, optionsType.New <EntityContextOptions>(serviceProvider));

            setupAction?.Invoke(builder);
            return(builder.Options);
        }
示例#5
0
 protected override void OnConfiguring(EntityContextOptionsBuilder builder)
 {
     builder.Options.NotifyEvents = true;
     //builder.UseOracleTrigger<Orders>().UseOracleTrigger<Products>().UseCodeFirst();
     //builder.UseEnvironment(s => s.AddVariable("Year", "2009")).UseCodeFirst();
     //builder.UseCodeFirst();
     base.OnConfiguring(builder);
 }
示例#6
0
            protected override void OnConfiguring(EntityContextOptionsBuilder builder)
            {
                var map = new PropertyMapInfo {
                    IsPrimaryKey = true, DataType = System.Data.DbType.Boolean, Description = "dd"
                };
                var p = new GeneralProperty {
                    Info = map
                };

                PropertyUnity.RegisterProperty(typeof(SysUser), p);
                builder.UseSqlServer(connstr);
            }
示例#7
0
        /// <summary>
        /// 使 <see cref="IServiceCollection"/> 能够使用 Fireasy 中的 <see cref="EntityContext"/> 对象。
        /// </summary>
        /// <param name="services"></param>
        /// <param name="setupAction"></param>
        /// <returns></returns>
        public static EntityContextOptionsBuilder AddEntityContext <TContext>(this IServiceCollection services, Action <EntityContextOptions> setupAction = null) where TContext : EntityContext
        {
            var options = new EntityContextOptions();

            setupAction?.Invoke(options);

            var builder = new EntityContextOptionsBuilder(options);

            if (setupAction != null)
            {
                services.Configure(setupAction);
            }

            services.AddScoped(s => options);
            services.AddScoped <TContext>();

            return(builder);
        }
示例#8
0
        public static void UseMongoDb <TContext>(this EntityContextOptionsBuilder <TContext> builder,
                                                 string connectionString,
                                                 string database,
                                                 EventQueueType eventQueueType = EventQueueType.InMemory)
            where TContext : EntityContext
        {
            RegisterConventions(MongoDB.Bson.GuidRepresentation.Standard);

            var options = new MongoEntityContextOptions <TContext>
            {
                ConnectionString = connectionString,
                DatabaseName     = database,
            };

            builder.Builder
            .Services
            .AddSingleton(options)
            .AddTransient <IDatabaseTransactionManager <TContext>, MongoDatabaseTransactionManager <TContext> >()
            .AddScoped <IDatabaseCollectionProvider <TContext>, MongoDatabaseCollectionProvider <TContext> >()
            .AddScoped <MongoDatabaseFactory <TContext> >()
            .AddSingleton <MongoClientFactory <TContext> >()
            .AddEventQueue <TContext>(eventQueueType);
        }
示例#9
0
 protected override void OnConfiguring(EntityContextOptionsBuilder builder)
 {
     builder.UseSqlServer(connstr);
 }
示例#10
0
 /// <summary>
 /// 配置 <see cref="EntityContext"/> 使用 MongoDB 数据库。
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="connectionString">连接字符串。<para>示例:server=mongodb://localhost;database=test。</para></param>
 public static void UseMongoDB(this EntityContextOptionsBuilder builder, string connectionString)
 {
     builder.Options.Provider         = MongoDBProvider.Instance;
     builder.Options.ConnectionString = connectionString;
 }