C# 无法将lambda表达式转换为类型“DbContextOptions”,因为它不是委托类型

C# 无法将lambda表达式转换为类型“DbContextOptions”,因为它不是委托类型,c#,.net-core,asp.net-identity,entity-framework-core,C#,.net Core,Asp.net Identity,Entity Framework Core,我创建了从类IdentityDbContext继承的类DataContext: using ProjDAL.Entities; using ProjDAL.Relations; using ProjDAL.Services; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design;

我创建了从类IdentityDbContext继承的类DataContext:

using ProjDAL.Entities;
using ProjDAL.Relations;
using ProjDAL.Services;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;

namespace ProjDAL.EF
{
    public class DataContext : IdentityDbContext<ApplicationUser>
    {

        public DataContext(DbContextOptions<DataContext> options) : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
        }
.......................................................
}
My Program.cs文件:

using System;
using DbInitialize.Provider;
using ProjDAL.EF;

namespace DbInitialize
{
    class Program
    {
        private static readonly DbInitializeProvider _db;
        delegate void Display();

        static Program()
        {
            _db = new DbInitializeProvider();
        }

        static void Main(string[] args)
        {
            try
            {
                Display display = _db.SetCreateDatabase;
                display.Invoke();

                Console.WriteLine($"\r\n{new string('-', 80)}");
                Console.WriteLine("For continue press any button...");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadLine();
        }
    }
}
I get错误:无法将lambda表达式转换为DbContextOptions类型,因为它不是委托类型创建DataContext实例和设置选项参数的正确性如何

如果你需要更多的信息,请告诉我。谢谢您的帮助。

创建DataContext类时,参数与DataContext构造函数中定义的参数不匹配。它需要DbContextOptions类型的对象,但您正在提供一个带有选项参数options=>options.UseSqlServerData Source=.\\SQLEXPRESS;初始目录=ProjAppTest;综合安全=真实;MultipleActiveResultSets=true

您需要构建options对象并向构造函数提供实例:

var optionsBuilder = new DbContextOptionsBuilder<DataContext>();
optionsBuilder.UseSqlServer("YOUR CONNECTION STRING");

_db = new DataContext(optionsBuilder.Options)
或者,您也可以使用不带参数的构造函数,并在OnConfigurang方法的DataContext类中对其进行配置

请参阅此处的文档:

var optionsBuilder = new DbContextOptionsBuilder<DataContext>();
optionsBuilder.UseSqlServer("YOUR CONNECTION STRING");

_db = new DataContext(optionsBuilder.Options)