Thursday, August 1, 2019

Core 2.2 db connection or Core 2.2 database connection

1. Update in root file appsettings.json like web.config

{
  "ConnectionStrings": {
    "DefaultConnection1": "Server=omg;Database=test;User Id=sa;Password=mdts888;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*"
}


2. Update in Startup.cs



    services.AddDbContext<db_context>(options =>
        options.UseSqlServer(
            Configuration.GetConnectionString("DefaultConnection1")));

    services.AddDbContext<db_context_>(options =>
                options.UseSqlServer(
                    Configuration.GetConnectionString("DefaultConnection1")));





3.

using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication6.Models;

namespace WebApplication6.Auth
{
    public class db_context : IdentityDbContext
    {
        public db_context(DbContextOptions<db_context> options)
            : base(options)
        {
        }
        public DbSet<WebApplication6.Models.customer> customer { get; set; }

    }

    public class db_context_ : DbContext
    {
        public db_context_(DbContextOptions<db_context> options)
            : base(options)
        {
        }
        public DbSet<WebApplication6.Models.customer> customer { get; set; }

    }
}



4. Installed Package




No comments:

Post a Comment

Linq Expression syntax for where condtion in linq

(Expression<Func<T, bool>> filter)