示例#1
0
        static DynamicContext CreateContext(string connectionString, Type targetType)
        {
            var modelOptions = new ModelOptions {
                ModelType = targetType
            };

            var collection = new ServiceCollection();

            collection.AddLogging(builder => {
                builder.AddConsole();
            });

            collection.AddSingleton <ModelOptions>(modelOptions);
            collection.AddDbContext <DynamicContext>(builder => {
                builder.UseNpgsql(connectionString);
            });

            var provider = collection.BuildServiceProvider();
            var context  = provider.GetService <DynamicContext>();

            return(context);
        }
示例#2
0
 public DynamicContext(DbContextOptions options, ModelOptions modelOptions) : base(options)
 {
     this.modelOptions = modelOptions;
 }