novusconsulting edited this page Sep 17, 2018 · 2 revisions

What is NovusConsulting.Data.SqlServer?

NovusConsulting.Data.SqlServer is a C# .NET Core class library. It is an implementation of the NovusConsulting.Data library for the Microsoft SQL Server Provider. It contains the following types:

  • ColumnConfiguration
  • EtlExtractionConfiguration
  • EtlFileConfiguration
  • EtlMappingRuleConfiguration
  • EtlProcessConfiguration
  • EtlProcessTransactionConfiguration
  • EtlProcessWorkflowConfiguration
  • EtlTransformationConfiguration
  • OperationConfiguration
  • PrivilegeConfiguration
  • ReportConfiguration
  • RoleConfiguration
  • SchemaConfiguration
  • TableConfiguration
  • UserConfiguration
  • UserLogConfiguration
  • UserRoleConfiguration
  • UserSessionConfiguration
  • ApplicationDbContext
  • DataLayer
  • Repository

Where can I get NovusConsulting.Data.SqlServer?

You can get it via nuget at https://www.nuget.org/packages/NovusConsulting.Data.SqlServer/

How do I use NovusConsulting.Data.SqlServer?

Extending the application database context with your own implementation

    public class ApplicationDbContext : NovusConsulting.Data.SqlServer.V1.ApplicationDbContext
    {
        public ApplicationDbContext(string connectionString) : base(connectionString)
        {
            _connectionString = connectionString;
        }
        public DbSet<Contact> Contact { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer(_connectionString);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ApplyConfiguration(new ContactConfiguration());
            base.OnModelCreating(modelBuilder);
        }
    }

Extending the data layer with your own implementation

    public class DataLayer : NovusConsulting.Data.SqlServer.V1.DataLayer
    {
        public DataLayer(DbContext dbContext, ConfigurationModel configuration) : base(dbContext, configuration) { }
    }

Injecting the data layer in your implementation

            var configuration = new ConfigurationModel()
            {
                JwtKey = "",
                JwtIssuer = "",
                MasterConnectionString = "",
                EntityFrameworkConnectionString = "",
                SqlConnectionString = "",
                FilePath = "",
                Olap = "",
                Processor = "",
                Localization = "",
                UseProxy = false,
                ProxyUrl = "",
                GeneratePostLogs = false,
                GeneratePutLogs = false,
                GenerateDeleteLogs = false,
                GenerateGetLogs = false,
                AdministrationSchema = ""
            };
            services.AddScoped<IDataLayer>(implementation => new Contacts.Api.V1.Data.DataLayer(new Contacts.Api.V1.Data.ApplicationDbContext(configuration.EntityFrameworkConnectionString), configuration));

Seeding the data

            //Seed => https://stackoverflow.com/questions/45885019/asp-net-core-2-get-instance-of-dbcontext?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
            var webHost = CreateWebHostBuilder(args).Build();
            var serviceScopeFactory = (IServiceScopeFactory)webHost.Services.GetService(typeof(IServiceScopeFactory));
            using (var scope = serviceScopeFactory.CreateScope())
            {
                try
                {
                    var services = scope.ServiceProvider;
                    var dataLayer = services.GetRequiredService<IDataLayer>();
                    dataLayer.Seed();
                }
                catch (Exception exception)
                {
                    var message = string.Format("{0}: {1}", exception.Message, exception.StackTrace);
                    Console.WriteLine(message);
                }
            }
            webHost.Run();
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.