时间:2021-07-01 10:21:17 帮助过:14人阅读
Startup.cs中的代码:
using System; using System.Linq; using Microsoft.AspNet.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Data.Entity; using CNBlogs.AboutUs.Data; using Microsoft.Dnx.Runtime; using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.Configuration; using System.Data.SqlClient; using Microsoft.Extensions.Logging; namespace CNBlogs.AboutUs.Web { public class Startup { public Startup(IApplicationEnvironment appEnv) { IConfigurationBuilder builder = new ConfigurationBuilder() .SetBasePath(appEnv.ApplicationBasePath) .AddJsonFile("config.json", false); Configuration = builder.Build(); } public IConfiguration Configuration { get; set; } public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); app.UseDeveloperExceptionPage(); app.UseMvcWithDefaultRoute(); app.UseStaticFiles(); app.UseRuntimeInfoPage(); } public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddEntityFramework() .AddSqlServer() .AddDbContext<EfDbContext>(options => { options.UseSqlServer(Configuration["data:ConnectionString"]); }); services.AddTransient<ITabNavRepository, TabNavRepository>(); } } }
.NET跨平台之旅:升级至ASP.NET 5 RC1,Linux上访问SQL Server数据库
标签: