Database creates (entity framework)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace test.Controllers
|
||||
namespace EntityFrameworkBasics.Controllers
|
||||
{
|
||||
public class AboutController : Controller
|
||||
{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
|
||||
namespace test.Controllers
|
||||
namespace EntityFrameworkBasics.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
|
||||
39
ASP.Net Core/MVCBasics/Data/ApplicationDBContext.cs
Normal file
39
ASP.Net Core/MVCBasics/Data/ApplicationDBContext.cs
Normal 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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
21
ASP.Net Core/MVCBasics/Data/SettingsDataModel.cs
Normal file
21
ASP.Net Core/MVCBasics/Data/SettingsDataModel.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System.IO;
|
||||
|
||||
namespace test
|
||||
namespace EntityFrameworkBasics
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
|
||||
@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace test
|
||||
namespace EntityFrameworkBasics
|
||||
{
|
||||
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.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
using(var context = new ApplicationDBContext())
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
services.AddMvc();
|
||||
}
|
||||
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
@using test
|
||||
@using EntityFrameworkBasics
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27130.2010
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29509.3
|
||||
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
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
Reference in New Issue
Block a user