locked
How to scaffold identity tables to an existing oracle database schema RRS feed

Answers

  • User-854763662 posted

    Hi poR ,

    where is the migration file located?

    After you run the command dotnet ef migrations add  MigrationName , three files are added to your project under the Data/Migrations directory:

    • XXXXXXXXX_InitialCreate.cs--The main migrations file. Contains the operations necessary to apply the migration (in Up()) and to revert it (in Down()).
    • XXXXXXXXX_InitialCreate.Designer.cs--The migrations metadata file. Contains information used by EF.
    • MyContextModelSnapshot.cs--A snapshot of your current model. Used to determine what changed when adding the next migration.

    You could refer to here for more about migrations.

    Best Regards ,

    Sherry

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 28, 2019 2:35 AM

All replies

  • User475983607 posted

    You need the EF Core Oracle provider.

    https://docs.microsoft.com/en-us/ef/core/providers/

    Friday, May 24, 2019 1:28 PM
  • User915516305 posted

    Thanks - have already installed oracle.entity.framework.core in project and put using using Oracle.EntityFrameworkCore;  in startup.cs but not sure if have all steps before i run below and how can tell it to use oracle database - using vs code?

    dotnet ef migrations add CreateIdentitySchema dotnet ef database update

    <section class="primary-holder column is-two-thirds-tablet is-three-quarters-desktop">
    <main class="content " id="main" role="main" lang="en-us" dir="ltr" data-bi-name="content">
    Oracle.EntityFrameworkCore

    and have appsettings.json

    {
      "Logging": {
        "LogLevel": {
          "Default": "Warning"
        }
      },
      "AllowedHosts": "*",
      "ConnectionStrings": {
        //"ncidentityIdentityDbContextConnection": "Server=(localdb)\\mssqllocaldb;Database=ncidentity;Trusted_Connection=True;MultipleActiveResultSets=true"
        "ncidentityIdentityDbContextConnection": "User Id=<uname>;Password=<pwd>;Data Source=<SID>;"
      }
    }

    startup.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.HttpsPolicy;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.EntityFrameworkCore;
    using Oracle.EntityFrameworkCore; 
    
    namespace ncidentity
    {
        public class Startup
        {
            public Startup(IConfiguration configuration)
            {
                Configuration = configuration;
            }
    
            public IConfiguration Configuration { get; }
    
            // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                
                services.AddMvc();
                services.Configure<CookiePolicyOptions>(options =>
                {
                    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                    options.CheckConsentNeeded = context => true;
                    options.MinimumSameSitePolicy = SameSiteMode.None;
                });
    
          
                //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    
               // services.AddDbContext<RazorCRUDContext>(options =>
               // options.UseOracle(Configuration.GetConnectionString("ncidentityIdentityDbContextConnection")));
    
                services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            }
    
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseExceptionHandler("/Error");
                    app.UseHsts();
                }
    
                app.UseHttpsRedirection();
                app.UseStaticFiles();
    
                app.UseAuthentication();
    
                app.UseCookiePolicy();
    
                app.UseMvc();
            }
        }
    }
    

    </main>
    </section>
    Friday, May 24, 2019 1:39 PM
  • User475983607 posted

    The instructions for scaffolding Identity are published here; https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.2&tabs=visual-studio

    If you need CLI commands then click the CLI tab; https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.2&tabs=netcore-cli

    As long as the DB connection works then you should be able to create a migration and update the database.  Are you having a problem or receiving an error?

    Friday, May 24, 2019 2:02 PM
  • User915516305 posted

    thanks

    looking to run

    dotnet ef database update

    from https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.2&tabs=netcore-cli

    just want to check existing unrelated data tables on the schema are unaffected - if could confirm please what the command

    dotnet ef database update  does exactly that would be great - new to .net ef core

    Friday, May 24, 2019 2:17 PM
  • User475983607 posted

    Create a test app if you are unsure. 

    Friday, May 24, 2019 2:18 PM
  • User915516305 posted

    this is a brand new test app - just want to make sure what happens when run command dotnet ef database update so as doesn't affect existing tables on the schema/database.

    is this the case that dotnet ef database update will only look to create identity tables

    jus using https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.2&tabs=netcore-cli

    Friday, May 24, 2019 2:45 PM
  • User475983607 posted

    this is a brand new test app - just want to make sure what happens when run command dotnet ef database update so as doesn't affect existing tables on the schema/database.

    is this the case that dotnet ef database update will only look to create identity tables

    jus using https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.2&tabs=netcore-cli

    Again, I recommend creating a test app if you are worried about affecting the schema.  IMHO, this is pretty step that you could have completed in the time it takes to post a question on the forum.  Otherwise, post enough code where the community can test it for you.  

    Friday, May 24, 2019 2:51 PM
  • User915516305 posted

    Have a schema on database with lots of existing tables totally unrelated to .net - just data tables.

    appreciate could just run command but wanted to know what the dotnet ef database update command does exactly as this would save having to restore database if command somehow does affect  unrelated tables - guessing just updates/creates tables affected/required by the application but cannot find exact definition of what it does

    Looking to run just the 2 commands below and check any unrelated existing tables on database remain in place with data

    this based on https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.2&tabs=netcore-cli

    dotnet new webapp --auth Individual -o WebApp1
    dotnet ef database update
    

    dotnet ef database update

    Friday, May 24, 2019 3:13 PM
  • User-854763662 posted

    Hi poR ,

    About using Entity Framework Core Implementation of ASP.NET Core Identity for Oracle, you could refer to the following links :

    https://www.devart.com/dotconnect/oracle/docs/Identity-3-Tutorial.html

    https://entityframeworkcore.com/providers-oracle

    dotnet ef database updateupdates the database to the last migration or to a specified migration( In general , make corresponding modifications to the tables involved in the migration file in the database.).

    As mgebhard suggested , you could  create a test app if you are worried about affecting the schema . 

    Best Regards ,

    Sherry

    Monday, May 27, 2019 8:23 AM
  • User915516305 posted

    Hi Sherry,

    Have ran test one on sqllite and can see creates 7 tables with dotnet ef database update command - where is the migration file located?

    can see some files in data/migrations after running the

    would now like to run on our test oracle database.

    dotnet ef database updateupdates the database to the last migration or to a specified migration( In general , make corresponding modifications to the tables involved in the migration file in the database.).

    Thanks

    Monday, May 27, 2019 9:17 AM
  • User-854763662 posted

    Hi poR ,

    where is the migration file located?

    After you run the command dotnet ef migrations add  MigrationName , three files are added to your project under the Data/Migrations directory:

    • XXXXXXXXX_InitialCreate.cs--The main migrations file. Contains the operations necessary to apply the migration (in Up()) and to revert it (in Down()).
    • XXXXXXXXX_InitialCreate.Designer.cs--The migrations metadata file. Contains information used by EF.
    • MyContextModelSnapshot.cs--A snapshot of your current model. Used to determine what changed when adding the next migration.

    You could refer to here for more about migrations.

    Best Regards ,

    Sherry

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 28, 2019 2:35 AM
  • User915516305 posted

    Hi,

    Thanks for reply.

    Tuesday, May 28, 2019 9:18 AM