moving some commands over to ef
This commit is contained in:
parent
a343fa2d7f
commit
731b2cf9b7
@ -1,6 +1,8 @@
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newsbot.Collector.Domain.Entities;
|
||||
using Newsbot.Collector.Domain.Interfaces;
|
||||
using Newsbot.Collector.Domain.Models;
|
||||
using Npgsql;
|
||||
@ -11,9 +13,12 @@ public class ArticlesTable : IArticlesRepository
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
|
||||
private DatabaseContext _context;
|
||||
|
||||
public ArticlesTable(string connectionString)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_context = new DatabaseContext(connectionString);
|
||||
}
|
||||
|
||||
public ArticlesTable(IConfiguration configuration)
|
||||
@ -22,12 +27,24 @@ public class ArticlesTable : IArticlesRepository
|
||||
if (conn is null) conn = "";
|
||||
|
||||
_connectionString = conn;
|
||||
_context = new DatabaseContext(conn);
|
||||
}
|
||||
|
||||
public List<ArticlesModel> List(int page = 0, int count = 25)
|
||||
public async Task<List<ArticlesEntity>> ListAsync(int page = 0, int count = 25)
|
||||
{
|
||||
await using var context = new DatabaseContext(_connectionString);
|
||||
var query = context.Articles
|
||||
.OrderBy(d => d.PubDate)
|
||||
.Take(25);
|
||||
Console.WriteLine(query.ToQueryString());
|
||||
await query.ToListAsync();
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
public List<ArticlesEntity> List(int page = 0, int count = 25)
|
||||
{
|
||||
using var conn = OpenConnection(_connectionString);
|
||||
var res = conn.Query<ArticlesModel>(@"select * from articles
|
||||
var res = conn.Query<ArticlesEntity>(@"select * from Articles
|
||||
Order By PubDate Desc
|
||||
Offset @Page
|
||||
Fetch Next @Count Rows Only", new
|
||||
@ -70,7 +87,16 @@ public class ArticlesTable : IArticlesRepository
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public ArticlesModel New(ArticlesModel model)
|
||||
public ArticlesEntity New(ArticlesEntity model)
|
||||
{
|
||||
using var context = new DatabaseContext(_connectionString);
|
||||
model.Id = new Guid();
|
||||
var query = context.Articles.Add(model);
|
||||
context.SaveChanges();
|
||||
return model;
|
||||
}
|
||||
|
||||
public ArticlesModel NewDapper(ArticlesModel model)
|
||||
{
|
||||
model.ID = Guid.NewGuid();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user