Database creates (entity framework)

This commit is contained in:
2020-01-22 20:30:40 +01:00
parent 076d0e94d4
commit 137417fde8
9 changed files with 73 additions and 8 deletions

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace test.Controllers namespace EntityFrameworkBasics.Controllers
{ {
public class AboutController : Controller public class AboutController : Controller
{ {

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
namespace test.Controllers namespace EntityFrameworkBasics.Controllers
{ {
public class HomeController : Controller public class HomeController : Controller
{ {

View File

@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EntityFrameworkBasics
{
/// <summary>
/// The database representational model for application
/// </summary>
public class ApplicationDBContext : DbContext
{
#region Public properties
public DbSet<SettingsDataModel> Settings { get; set; }
#endregion
public ApplicationDBContext()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
// tfoUbuntu;User ID=sa;Password=********;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
//optionsBuilder.UseSqlServer("Server=192.168.0.135;Database=entityframework;")
optionsBuilder.UseSqlServer("Server=192.168.0.135;Database=entityframework;User ID=sa;Password=SAtfoubuntu1SA;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;MultipleActiveResultSets=true;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
}

View File

@ -0,0 +1,21 @@
namespace EntityFrameworkBasics
{
/// <summary>
/// Our Settings database table representional model
/// </summary>
public class SettingsDataModel
{
/// <summary>
/// The unique Id for this entry
/// </summary>
public string Id { get; set; }
/// <summary>
/// The settings name
/// </summary>
public string Name { get; set; }
/// <summary>
/// The settings value
/// </summary>
public string Value { get; set; }
}
}

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using System.IO; using System.IO;
namespace test namespace EntityFrameworkBasics
{ {
public class Program public class Program
{ {

View File

@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace test namespace EntityFrameworkBasics
{ {
public class Startup public class Startup
{ {
@ -21,6 +21,11 @@ namespace test
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
using(var context = new ApplicationDBContext())
{
context.Database.EnsureCreated();
}
services.AddMvc(); services.AddMvc();
} }

View File

@ -1,2 +1,2 @@
@using test @using EntityFrameworkBasics
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -1,9 +1,9 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio Version 16
VisualStudioVersion = 15.0.27130.2010 VisualStudioVersion = 16.0.29509.3
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test", "test.csproj", "{B6C91DFF-E4A2-4DD3-A357-F8BECCCA183A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkBasics", "EntityFrameworkBasics.csproj", "{B6C91DFF-E4A2-4DD3-A357-F8BECCCA183A}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution