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.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LaDOSE.Api.Context;
|
||||
using LaDOSE.Entity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LaDOSE.Api.Controllers
|
||||
@@ -10,11 +12,20 @@ namespace LaDOSE.Api.Controllers
|
||||
[ApiController]
|
||||
public class ConfigController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly LaDOSEDbContext _db;
|
||||
|
||||
public ConfigController(LaDOSEDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
// GET api/Config
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
public ActionResult<IEnumerable<Game>> Get()
|
||||
{
|
||||
return new string[] { "value1", "value2" };
|
||||
|
||||
return _db.Game.ToList();
|
||||
|
||||
}
|
||||
|
||||
// GET api/Config/5
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LaDOSE.Entity\LaDOSE.Entity.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -2,14 +2,18 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LaDOSE.Api.Context;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Pomelo.EntityFrameworkCore.MySql;
|
||||
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
|
||||
|
||||
namespace LaDOSE.Api
|
||||
{
|
||||
@@ -26,7 +30,16 @@ namespace LaDOSE.Api
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
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.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
|
||||
Reference in New Issue
Block a user