mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-04 13:57:37 +00:00
Initial commit
This commit is contained in:
parent
1d9d051759
commit
9656378279
557 changed files with 182300 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
using Microsoft.EntityFrameworkCore; // UseSqlServer
|
||||
using Microsoft.Extensions.DependencyInjection; // IServiceCollection
|
||||
|
||||
namespace Packt.Shared;
|
||||
|
||||
public static class NorthwindContextExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds NorthwindContext to the specified IServiceCollection. Uses the SqlServer database provider.
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="connectionString">Set to override the default.</param>
|
||||
/// <returns>An IServiceCollection that can be used to add more services.</returns>
|
||||
public static IServiceCollection AddNorthwindContext(
|
||||
this IServiceCollection services,
|
||||
string connectionString = "Data Source=.;Initial Catalog=Northwind;" +
|
||||
"Integrated Security=true;MultipleActiveResultsets=true;Encrypt=false")
|
||||
{
|
||||
services.AddDbContext<NorthwindContext>(options =>
|
||||
{
|
||||
options.UseSqlServer(connectionString);
|
||||
|
||||
options.LogTo(WriteLine, // Console
|
||||
new[] { Microsoft.EntityFrameworkCore
|
||||
.Diagnostics.RelationalEventId.CommandExecuting });
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue