Próbuję zaimplementować Entity Framework 7 w MVC 6, a na tej stronie here mówi zrobićmetoda UseSqlServer brakuje MVC 6
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
ale dla mnie metoda UseSqlServer
isnt widoczne? Czy ktoś wie, jak go pokazać? Czy jest to stary sposób konfigurowania struktury encji?
Mój plik startup.cs wygląda to
using FluentValidation;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;
namespace me.namespace.project
{
public class Startup
{
public static IConfiguration Configuration { get; set; }
public Startup(IHostingEnvironment env)
{
// Setup configuration sources.
Configuration = new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables();
}
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// entity framework
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<DataContext>();
}
}
}
Dziękuję To jest dokładnie to, co potrzebne – Gillardo
działa doskonale ... teraz mam inny problem "Nie skonfigurowano żadnych dostawców baz danych. Skonfiguruj dostawcę bazy danych przez przesłonięcie OnConfiguring w twojej klasie DbContext lub w metodzie AddDbContext podczas konfigurowania usług. "Nie wiesz dlaczego, ponieważ mój plik startup.cs podaje conectionstring? – Gillardo
Dźwięki łatwe do naprawienia, ale to kolejne pytanie :) – DavidG