Entity Framework Core 2.0 wurde recently released und ich verwende es.Entity Framework Core 2 - Code zuerst nicht Tabellen erstellen
Ich habe die folgende Zeile in der Methode ConfigurationServices() in der Datei Startup.cs (Mein Connectionstring ist in Ordnung) hinzugefügt.
services.AddDbContext<AutoPartsContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("NetCore")));
und in Verfahren konfigurieren,
using (var serviceScope =
app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
var context =
serviceScope.ServiceProvider.GetRequiredService<MyConntectionStringName>();
context.Database.Migrate();
context.Database.EnsureCreated();
}
Dies wird die Erstellung der Datenbank, aber keine Tabellen. Wenn ich rufe eine einfache Zählung auf meine Tabellen,
var a = _context.Users.Count();
Es wirft Ausnahme folgende
Ungültige Objektnamen ‚Benutzer‘. bei System.Data.SqlClient.SqlConnection.OnError (SqlException Ausnahme, Boolean Breakconnection, Action`1 wrapCloseInAction)
Wenn jedoch i Tabelle manuell erstellen, funktioniert alles perfekt. Ich brauche alle Tabellen automatisch erstellt werden.
EF Core-Version: 2.0, Datenbankanbieter: Microsoft.EntityFrameworkCore.SqlServer, Betriebssystem: Windows 10, IDE: Visual Studio 2017 Preview 2
Danke, das hat geholfen – Mohsin