private static IModel GetCompiled(DbContextOptionsBuilder <mphContext> optionsBuilder, string schema) { //https://github.com/aspnet/EntityFramework/issues/3909 //var serviceCollection = new ServiceCollection(); //serviceCollection.AddEntityFramework().AddSqlServer(); //var serviceProvider = serviceCollection.BuildServiceProvider(); var coreConventionSetBuilder = new CoreConventionSetBuilder(null); //var sqlConventionSetBuilder = new SqlServerConventionSetBuilder(new SqlServerTypeMapper()); //var conventionSet = sqlConventionSetBuilder.AddConventions(coreConventionSetBuilder.CreateConventionSet()); var conventionSet = coreConventionSetBuilder.CreateConventionSet(); var builder = new ModelBuilder(conventionSet); builder.Entity <alphadigit>(); builder.Entity <langid>(); builder.Entity <word_param>(); builder.Entity <gr>(); builder.Entity <indents>(); builder.Entity <accent>(); builder.Entity <parts>(); builder.Entity <flexes>(); builder.Entity <accents_class>(); builder.Entity <minor_acc>(); //Cal Manually OnModelCreating from base class to create model objects relatet di Asp.Net identity (not nice) (new mphContext(optionsBuilder.Options, schema)).OnModelCreating(builder); //builder.Entity<Invoice>().ToTable("REGION", schema); return(builder.Model); }
private static IModel GetCompiled(DbContextOptionsBuilder <etymContext> optionsBuilder, string schema) { //https://github.com/aspnet/EntityFramework/issues/3909 //var serviceCollection = new ServiceCollection(); //serviceCollection.AddEntityFramework().AddSqlServer(); //var serviceProvider = serviceCollection.BuildServiceProvider(); var coreConventionSetBuilder = new CoreConventionSetBuilder(null); //var sqlConventionSetBuilder = new SqlServerConventionSetBuilder(new SqlServerTypeMapper()); //var conventionSet = sqlConventionSetBuilder.AddConventions(coreConventionSetBuilder.CreateConventionSet()); var conventionSet = coreConventionSetBuilder.CreateConventionSet(); var builder = new ModelBuilder(conventionSet); builder.Entity <bibl>(); builder.Entity <e_classes>(); builder.Entity <etymons>(); builder.Entity <lang_all>(); builder.Entity <links>(); builder.Entity <root>(); //Cal Manually OnModelCreating from base class to create model objects relatet di Asp.Net identity (not nice) (new etymContext(optionsBuilder.Options, schema)).OnModelCreating(builder); //builder.Entity<Invoice>().ToTable("REGION", schema); return(builder.Model); }
private static IQueryable SelectQuery(Type typeRow) { var conventionBuilder = new CoreConventionSetBuilder(); var conventionSet = conventionBuilder.CreateConventionSet(); var builder = new ModelBuilder(conventionSet); { var entity = builder.Entity(typeRow); SqlNameAttribute attributeRow = (SqlNameAttribute)typeRow.GetTypeInfo().GetCustomAttribute(typeof(SqlNameAttribute)); entity.ToTable(attributeRow.SqlName); foreach (PropertyInfo propertyInfo in typeRow.GetTypeInfo().GetProperties()) { SqlNameAttribute attributeProperty = (SqlNameAttribute)propertyInfo.GetCustomAttribute(typeof(SqlNameAttribute)); entity.Property(propertyInfo.PropertyType, propertyInfo.Name).HasColumnName(attributeProperty.SqlName); } } var options = new DbContextOptionsBuilder <DbContext>(); options.UseSqlServer(Framework.Server.ConnectionManager.ConnectionString); options.UseModel(builder.Model); DbContext dbContext = new DbContext(options.Options); dbContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; // For SQL views. No primary key. IQueryable query = (IQueryable)(dbContext.GetType().GetTypeInfo().GetMethod("Set").MakeGenericMethod(typeRow).Invoke(dbContext, null)); return(query); }
/// <summary> /// Creates the convention set to be used for the model. Uses the <see cref="CoreConventionSetBuilder" /> /// if <paramref name="conventionSetBuilder" /> is null. /// </summary> /// <param name="conventionSetBuilder"> The convention set builder to be used. </param> /// <returns> The convention set to be used. </returns> protected virtual ConventionSet CreateConventionSet([CanBeNull] IConventionSetBuilder conventionSetBuilder) { var conventionSet = CoreConventionSetBuilder.CreateConventionSet(); return(conventionSetBuilder == null ? conventionSet : conventionSetBuilder.AddConventions(conventionSet)); }
public GenericModelBuilder(IConfigurationRoot configuration) { var coreConventionSetBuilder = new CoreConventionSetBuilder(); var sqlConventionSetBuilder = new SqlServerConventionSetBuilder(new SqlServerTypeMapper(), null, null); var conventionSet = sqlConventionSetBuilder.AddConventions(coreConventionSetBuilder.CreateConventionSet()); modelBuilder = new ModelBuilder(conventionSet); this.configuration = configuration; }
public void UnitOfWorkSetup() { var csBuilder = new CoreConventionSetBuilder( new CoreConventionSetBuilderDependencies( new CoreTypeMapper( new CoreTypeMapperDependencies()))); var mb = new ModelBuilder(csBuilder.CreateConventionSet()); mb.Entity <Blog>(); mb.Entity <Post>(); mb.Entity <Category>(); var builder = new DbContextOptionsBuilder() .UseInMemoryDatabase(TestContext.TestName) .UseModel(mb.Model); uow = new UnitOfWork(builder.Options); repo = new Repository(uow); repo.UnitOfWork.Add(new Blog { Title = "Test Title", Posts = new List <Post>() { new Post { Title = "Foo", Body = "Bar", Categories = new List <Category> { new Category { Name = "Awesome" } } } } }); repo.UnitOfWork.Commit(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddDbContext <UnitOfWork>(opt => { opt.UseInMemoryDatabase("Test", im => { }); var csBuilder = new CoreConventionSetBuilder( new CoreConventionSetBuilderDependencies( new CoreTypeMapper( new CoreTypeMapperDependencies()))); var builder = new ModelBuilder(csBuilder.CreateConventionSet()); builder.Entity <Blog>(); builder.Entity <Post>(); opt.UseModel(builder.Model); }, contextLifetime: ServiceLifetime.Scoped, optionsLifetime: ServiceLifetime.Singleton); services.AddHighwayRestArea(); }