protected override void OnConfiguring(EntityContextOptionsBuilder builder) { //builder.Options.CacheParsing = false; builder.Options.CacheExecution = true; //builder.UseMongoDB("server=mongodb://localhost;database=test"); base.OnConfiguring(builder); }
/// <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); }
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); }
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); }
/// <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); }
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); }
protected override void OnConfiguring(EntityContextOptionsBuilder builder) { builder.UseSqlServer(connstr); }
/// <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; }