44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
using EFCore7Study.DataService;
|
|
using EFCore7Study.DataService.Models;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Internal;
|
|
|
|
namespace EFCore7Study.WebApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class EFCore2Controller : ControllerBase
|
|
{
|
|
private readonly AppDbContext2 _context;
|
|
private readonly IDbContextFactory<AppDbContext2> _factory;
|
|
|
|
public EFCore2Controller
|
|
(
|
|
AppDbContext2 context,
|
|
IDbContextFactory<AppDbContext2> factory
|
|
)
|
|
{
|
|
_context = context;
|
|
_factory = factory;
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<Account> GetAll()
|
|
{
|
|
return _context.Accounts.AsNoTracking().ToList();
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<Account> GetAllByFactory()
|
|
{
|
|
using (var db = _factory.CreateDbContext())
|
|
{
|
|
return db.Accounts.AsNoTracking().ToList();
|
|
}
|
|
}
|
|
}
|
|
}
|