The entity framework course is finished
This commit is contained in:
@ -6,10 +6,23 @@ namespace EntityFrameworkBasics.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
|
||||
#region Protected members
|
||||
|
||||
protected ApplicationDBContext context;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
/// <param name="_context">the injected context</param>
|
||||
public HomeController(ApplicationDBContext _context)
|
||||
{
|
||||
context = _context;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
// No using statement because of the DI and IoC
|
||||
var context = IoC.ApplicationDbContext;
|
||||
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
|
||||
@ -12,8 +12,6 @@ namespace EntityFrameworkBasics
|
||||
public class ApplicationDBContext : DbContext
|
||||
{
|
||||
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString("N");
|
||||
|
||||
#region Public properties
|
||||
|
||||
public DbSet<SettingsDataModel> Settings { get; set; }
|
||||
@ -36,6 +34,9 @@ namespace EntityFrameworkBasics
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
// Fluent Api
|
||||
modelBuilder.Entity<SettingsDataModel>().HasIndex(c => c.Name).IsUnique();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,6 @@ namespace EntityFrameworkBasics
|
||||
/// <summary>
|
||||
/// The settings name
|
||||
/// </summary>
|
||||
[Required]
|
||||
[MaxLength(256)]
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System.IO;
|
||||
|
||||
namespace EntityFrameworkBasics
|
||||
@ -12,9 +13,7 @@ namespace EntityFrameworkBasics
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args)
|
||||
{
|
||||
return new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
return WebHost.CreateDefaultBuilder()
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ namespace EntityFrameworkBasics
|
||||
{
|
||||
// Add ApplicationDbContext to DI
|
||||
services.AddDbContext<ApplicationDBContext>(options =>
|
||||
options.UseSqlServer("Server=192.168.0.135;Database=entityframework;User ID=sa;Password=SAtfoubuntu1SA;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;MultipleActiveResultSets=true;"));
|
||||
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
|
||||
services.AddMvc();
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=192.168.0.135;Database=entityframework;User ID=sa;Password=SAtfoubuntu1SA;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;MultipleActiveResultSets=true;"
|
||||
},
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
"LogLevel": {
|
||||
|
||||
Reference in New Issue
Block a user