52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNet.Builder;
|
|
using Microsoft.AspNet.Hosting;
|
|
using Microsoft.Data.Entity;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace DatabaseErrorPageSample
|
|
{
|
|
public class Startup
|
|
{
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddEntityFramework()
|
|
.AddSqlServer()
|
|
.AddDbContext<MyContext>(options => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=DatabaseErrorPageSample;Trusted_Connection=True;"));
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app)
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
app.UseDatabaseErrorPage();
|
|
app.Run(context =>
|
|
{
|
|
context.RequestServices.GetService<MyContext>().Blog.FirstOrDefault();
|
|
return Task.FromResult(0);
|
|
});
|
|
}
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
var application = new WebApplicationBuilder()
|
|
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
|
|
.UseStartup<Startup>()
|
|
.Build();
|
|
|
|
application.Run();
|
|
}
|
|
}
|
|
|
|
public class MyContext : DbContext
|
|
{
|
|
public DbSet<Blog> Blog { get; set; }
|
|
}
|
|
|
|
public class Blog
|
|
{
|
|
public int BlogId { get; set; }
|
|
public string Url { get; set; }
|
|
}
|
|
}
|