update to load the data in scope.

This commit is contained in:
Ben
2024-03-19 09:19:56 +08:00
parent 055e54966d
commit 0cafef7ab4
14 changed files with 46 additions and 58 deletions

View File

@ -9,25 +9,24 @@ namespace Oqtane.Repository
public class UrlMappingRepository : IUrlMappingRepository
{
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
private readonly TenantDBContext _queryContext;
private readonly ISiteRepository _sites;
public UrlMappingRepository(IDbContextFactory<TenantDBContext> dbContextFactory, ISiteRepository sites)
{
_dbContextFactory = dbContextFactory;
_queryContext = _dbContextFactory.CreateDbContext();
_sites = sites;
}
public IEnumerable<UrlMapping> GetUrlMappings(int siteId, bool isMapped)
{
using var db = _dbContextFactory.CreateDbContext();
if (isMapped)
{
return _queryContext.UrlMapping.Where(item => item.SiteId == siteId && !string.IsNullOrEmpty(item.MappedUrl)).Take(200);
return db.UrlMapping.Where(item => item.SiteId == siteId && !string.IsNullOrEmpty(item.MappedUrl)).Take(200).ToList();
}
else
{
return _queryContext.UrlMapping.Where(item => item.SiteId == siteId && string.IsNullOrEmpty(item.MappedUrl)).Take(200);
return db.UrlMapping.Where(item => item.SiteId == siteId && string.IsNullOrEmpty(item.MappedUrl)).Take(200).ToList();
}
}