0
I am starting a very simple project with net core 2.2 and confronted myself with the following error:
Cannot convert lambda expression to "Servicelifetime" type because it is not a delegated type
Archive startup.Cs
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<Menu>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
Model:
public class Menu
{
public int MenuID { get; set; }
public string NmMenu {get; set;}
public int MenuIdPai { get; set; }
}
Context:
public class Ctx: DbContext
{
public Ctx(DbContextOptions<Ctx> options)
: base(options)
{ }
public DbSet<Menu> Menus { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Menu>().ToTable("Menu");
}
}
appsettings:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=Ctx;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}