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.
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|