Asp.net 핵심 응용 프로그램을 만들고 데이터베이스에 연결하려고합니다. startup.cs 파일의 ConfigureServices 메서드에서 다음 코드 줄에 오류가 발생했습니다. 내가 얻는 오류는 값이 null 일 수 없다는 것입니다. web.config 파일에서 CustomerOrderEntities 키를 찾을 수없는 것 같습니다. 문제가 Startup.csAsp.Net 핵심 dbcontext 문제
services.AddDbContext<CustomerOrderEntities>(options =>
options.UseSqlServer(Configuration.GetConnectionString("CustomerOrderEntities")));
무엇인지 확실하지
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddDbContext<CustomerOrderEntities>(options =>
options.UseSqlServer(Configuration.GetConnectionString("CustomerOrderEntities")));
AutoMapperConfiguration.Configure();
// Create the container builder.
var builder = new ContainerBuilder();
// Register dependencies, populate the services from
// the collection, and build the container. If you want
// to dispose of the container at the end of the app,
// be sure to keep a reference to it as a property or field.
builder.RegisterType<UnitOfWork>().As<IUnitOfWork>();
builder.RegisterType<DbFactory>().As<IDbFactory>();
builder.RegisterType<CustomerRepository>().As<ICustomerRepository>();
builder.RegisterType<ProductRepository>().As<IProductRepository>();
builder.RegisterType<OrderRepository>().As<IOrderRepository>();
builder.Populate(services);
this.ApplicationContainer = builder.Build();
// Create the IServiceProvider based on the container.
return new AutofacServiceProvider(this.ApplicationContainer);
}
ASP.NET 코어에 연결 문자열이 appsettings.json에 정의되어
<connectionStrings>
<add name="CustomerOrderEntities" connectionString="metadata=res://*/EF.CustomerOrderContext.csdl|res://*/EF.CustomerOrderContext.ssdl|res://*/EF.CustomerOrderContext.msl;provider=System.Data.SqlClient;provider connection string="data source=test-PC\MSSQLSERVER2014;initial catalog=CodeFirstTest;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
EntityFramework 6를 사용하고 있습니까? 예를 들어 EFCore와 EF 코어는 web.config를 사용하지 않지만 asp.net 코어에있는 appsettings.json (및 로컬 개발에 대한 사용자 비밀)은 – Tseng
입니다. 우리는 web.config에 그런 종류의 물건을 저장하지 않습니다. web.config는 IIS 구성 전용이며 appsettings.json –
을 사용해야합니다. 죄송합니다. 그것은 entityframeworkcore 아니 6 – Tom