動くコード図鑑技術記事現場の渡り方キャリア論すべての記事About
C#

Start.csを修正する

出典: 【C#】Asp.net Core EFでSqlServerに対しマイグレーションをする方法フェーズ1:プロジェクト側 / Start.csを修正する

Start.csを修正する (csharp)#ec0b6d60debc
namespace sqlserver_connection_demo
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }
        private SqlConnectionStringBuilder stringBuilder = new SqlConnectionStringBuilder()
        {
            InitialCatalog = "DemoDB",
            DataSource = "localhost",
            UserID = "sa",
            Password = "sa"
        };
        public IConfiguration Configuration { get; }
 
    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllers();
        services.AddDbContext<DemoContext>(opt =>
        {
            opt.UseSqlServer(stringBuilder.ToString())
        })
    }
 
    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
 
        app.UseHttpsRedirection();
 
        app.UseRouting();
 
        app.UseAuthorization();
 
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }
}
▸ この snippet は実行結果未収録
▸ 実行結果は未収録です
  • id: #ec0b6d60debc
  • lines: 47
  • extracted: 2026-06-10

Source収録記事

この snippet は記事の「フェーズ1:プロジェクト側 / Start.csを修正する」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。

同じ記事から

4
図鑑トップ