Giter Club home page Giter Club logo

Comments (5)

ericbrunner avatar ericbrunner commented on May 18, 2024 1

Hi Damien,

Thanks for your quick reply. Well it was not so easy, To contribute , I summarized what was required to get the sample from your tutorial working for a MS SQL Server database:

Migration Steps from SQLite Server to MS SQL Server setup:

1. In Startup.cs comment out (or removed if unused) the SQLite related code statements and add that:

       // init database for localization
      var sqlConnectionString = Configuration["DbStringLocalizer:ConnectionString"];

       //services.AddDbContext<LocalizationModelContext>(options =>
       //     options.UseSqlite(
       //         sqlConnectionString, 
       //         b => b.MigrationsAssembly("AspNetCoreLocalization")
       // )
       //);
		
        services.AddDbContext<LocalizationModelContext>(options => 
        options.UseSqlServer(sqlConnectionString, sqlServerOptions => sqlServerOptions.MigrationsAssembly("AspNetCoreLocalization")));

Note: Remove that action delegate b => b.MigrationsAssembly("AspNetCoreLocalization") when including the Localization.SqlLocalizer as nuget! That action delegate is only required here in the source code project where the Localization.SqlLocalizer is added as a project reference to WebApp "AspNetCoreLocalization". The EF Migration Assembly is by default allways the project where the DbContext is located.

2. Attempt an initial EF migration

I like the Package Manager Console but that can be done from command line , too.
When you attempt to create an initial migration you will fail with that:

PM> Add-Migration Localization-Initial -Context LocalizationModelContext
Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("Localization.SqlLocalizer")). By default, the migrations assembly is the assembly containing the DbContext.
Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project.
Your target project 'Localization.SqlLocalizer' doesn't match your migrations assembly 'AspNetCoreLocalization'. Either change your target project or change your migrations assembly.

3. Get rid of all EF SQLite package (if not used!)

4. Add that EF MS SQL Server Runtime and Designer/Tools packages:
- Microsoft.EntityFrameworkCore.Tools v1.1.2 (at time of writing)
- Microsoft.EntityFrameworkCore.SqlServer v.1.1.2 (at time of writing)
- Microsoft.EntityFrameworkCore.SqlServer.Design v.1.1.1 (at time of writing)

5. Try again to start initial Migration

PM> Add-Migration Localization-Init -Context LocalizationModelContext
To undo this action, use Remove-Migration.
PM> Update-Database -Context LocalizationModelContext
Done.

Now it succeeds.

6. Verify that 3 Tables are created in your MS SQL Server database
- LocalizationRecords
- ExportHistoryDbSet
- ExportHistoryDbSet

from aspnetcorelocalization.

ericbrunner avatar ericbrunner commented on May 18, 2024 1

@damienbod Sure. I put that sample at https://github.com/ericbrunner/AspNetCoreLocalizationWithMSSQL

The connectionstring is templated:

  "DbStringLocalizer": {
    "ConnectionString": "Server=tcp:<YOUR-DATABASE>.database.windows.net,1433;Initial Catalog=<YOUR DATABASE>;Persist Security Info=False;User ID=<YOUR USERNAME>;Password=<YOUR PASSWORD>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
  }

I verified that it is working with an Azure MS SQL Server database.

Greetings Eric

from aspnetcorelocalization.

damienbod avatar damienbod commented on May 18, 2024

Hi Eric according to this Azure SQL Server can be used with EF Core.
http://stackoverflow.com/questions/38485246/ef-core-and-azure

This means that you just need to change the connection string in the app settings.

https://github.com/damienbod/AspNet5Localization/blob/master/src/AspNetCoreLocalization/Startup.cs#L36

from aspnetcorelocalization.

damienbod avatar damienbod commented on May 18, 2024

@ericbrunner excellent, thanks, I'll add this to the docs if it's ok with you.

Greetings Damien

from aspnetcorelocalization.

damienbod avatar damienbod commented on May 18, 2024

Hi @ericbrunner want to reopen this, will close it when I have included it in the docs. Will use your github name to reference you, unless you want else.

from aspnetcorelocalization.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.