You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.4 KiB
C#

using EFCore7Study.DataService;
using EFCore7Study.DataService.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace EFCore7Study.WebApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class EFCoreController : ControllerBase
{
private readonly AppDbContext _connect;
private readonly IDbContextFactory<AppDbContext> _factory;
public EFCoreController(AppDbContext context, IDbContextFactory<AppDbContext> factory)
{
_connect = context;
_factory = factory;
}
[HttpGet]
public List<Account> GetAll()
{
return _connect.Accounts.ToList();
}
[HttpGet]
public List<Account> GetAllByFactory()
{
using (var db = _factory.CreateDbContext())
{
return db.Accounts.ToList();
}
}
[HttpGet]
public List<Account> GetAll3()
{
return _connect.Accounts.ToList();
}
[HttpGet]
public List<Account> GetAll4()
{
return _connect.Accounts.ToList();
}
[HttpGet]
public List<Account> GetAll5()
{
return _connect.Accounts.ToList();
}
[HttpGet]
public List<Account> GetAll6()
{
return _connect.Accounts.ToList();
}
}
}