add-migration initial DbContext hata çözümü

ASP.Net MVC Core, C#, Ado.Net, Entity Framework, Windows Form, SQL Server, Console, HTML, CSS, JQuery, Web Api
Kullanıcı avatarı
AzS
1500+
1500+
Mesajlar: 8942
Kayıt: 02 Ağu 2019 08:10

add-migration initial DbContext hata çözümü

Mesaj gönderen AzS »

An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: MCTarz.DAL.Contexts.WebContext Lifetime: Scoped ImplementationType: MCTarz.DAL.Contexts.WebContext': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Microsoft.EntityFrameworkCore.DbContext]' while attempting to activate 'MCTarz.DAL.Contexts.WebContext'.)

Unable to create an object of type 'WebContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

WebContext.cs içerisinde en alta ekleyip add-migration initial çalıştır.

Kod: Tümünü seç

public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<WebContext>
{
    public WebContext CreateDbContext(string[] args)
    {
        var builder = new DbContextOptionsBuilder<WebContext>();
        var connectionString = "Server=serverAdınızıYazınız;Database=Veritabanı adınızıYazınız;Trusted_Connection=True;";
        builder.UseSqlServer(connectionString);
        return new WebContext(builder.Options);
    }
}
Yukarıdaki kodun en sonunda bulunan (builder.Options); ifadesinin altı kırmızı çizgiliyse aşağıdaki kodu aynı şekilde ekleyiniz.

Kod: Tümünü seç

public WebContext([NotNullAttribute] DbContextOptions options) : base(options) { }
ÖNEMLİ NOT:Kodlarda geçen WebContext ifadesi projelerimden birinde kullandığım Context dosyamın adıdır. WebContext olarak geçen kısımları kendi projenizde oluşturmuş olduğunuz Context ismiyle değiştirmeyi unutmayınız!!!
Yeni Başlık Cevapla

“Yazılım Uzmanlığı Ders Notları” sayfasına dön