Test EF / Mysql
This commit is contained in:
20
LaDOSE.Src/LaDOSE.Api/Context/LaDOSEDbContext.cs
Normal file
20
LaDOSE.Src/LaDOSE.Api/Context/LaDOSEDbContext.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
using System;
|
||||||
|
using LaDOSE.Entity;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
namespace LaDOSE.Api.Context
|
||||||
|
{
|
||||||
|
public class LaDOSEDbContext : DbContext
|
||||||
|
{
|
||||||
|
public DbSet<Game> Game { get; set; }
|
||||||
|
|
||||||
|
public LaDOSEDbContext(DbContextOptions options) : base(options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using LaDOSE.Api.Context;
|
||||||
|
using LaDOSE.Entity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace LaDOSE.Api.Controllers
|
namespace LaDOSE.Api.Controllers
|
||||||
@@ -10,11 +12,20 @@ namespace LaDOSE.Api.Controllers
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class ConfigController : ControllerBase
|
public class ConfigController : ControllerBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private readonly LaDOSEDbContext _db;
|
||||||
|
|
||||||
|
public ConfigController(LaDOSEDbContext db)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
}
|
||||||
// GET api/Config
|
// GET api/Config
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ActionResult<IEnumerable<string>> Get()
|
public ActionResult<IEnumerable<Game>> Get()
|
||||||
{
|
{
|
||||||
return new string[] { "value1", "value2" };
|
|
||||||
|
return _db.Game.ToList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET api/Config/5
|
// GET api/Config/5
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\LaDOSE.Entity\LaDOSE.Entity.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -2,14 +2,18 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using LaDOSE.Api.Context;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.HttpsPolicy;
|
using Microsoft.AspNetCore.HttpsPolicy;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using Pomelo.EntityFrameworkCore.MySql;
|
||||||
|
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
|
||||||
|
|
||||||
namespace LaDOSE.Api
|
namespace LaDOSE.Api
|
||||||
{
|
{
|
||||||
@@ -26,7 +30,16 @@ namespace LaDOSE.Api
|
|||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
|
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
|
||||||
|
services.AddDbContextPool<LaDOSEDbContext>( // replace "YourDbContext" with the class name of your DbContext
|
||||||
|
options => options.UseMySql("Server=localhost;Database=ladose;User=root;Password=;", // replace with your Connection String
|
||||||
|
mysqlOptions =>
|
||||||
|
{
|
||||||
|
mysqlOptions.ServerVersion(new Version(10, 1, 16), ServerType.MariaDb); // replace with your Server Version and Type
|
||||||
|
}
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||||
|
|||||||
11
LaDOSE.Src/LaDOSE.Entity/Game.cs
Normal file
11
LaDOSE.Src/LaDOSE.Entity/Game.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace LaDOSE.Entity
|
||||||
|
{
|
||||||
|
public class Game
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string ImgUrl { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
7
LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj
Normal file
7
LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -5,7 +5,9 @@ VisualStudioVersion = 15.0.28010.2041
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaDOSE.DiscordBot", "LaDOSE.DiscordBot\LaDOSE.DiscordBot.csproj", "{C1E8FAF6-3A75-44AC-938D-CA56A5322D1C}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaDOSE.DiscordBot", "LaDOSE.DiscordBot\LaDOSE.DiscordBot.csproj", "{C1E8FAF6-3A75-44AC-938D-CA56A5322D1C}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaDOSE.Api", "LaDOSE.Api\LaDOSE.Api.csproj", "{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaDOSE.Api", "LaDOSE.Api\LaDOSE.Api.csproj", "{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaDOSE.Entity", "LaDOSE.Entity\LaDOSE.Entity.csproj", "{B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -21,6 +23,10 @@ Global
|
|||||||
{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Release|Any CPU.Build.0 = Release|Any CPU
|
{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Reference in New Issue
Block a user