// ***********************************************************************
// Assembly : Repository
// Author : frede
// Created : 2023 06 10 14:18
//
// Last Modified By : frede
// Last Modified On : 2023 06 10 14:18
// ***********************************************************************
//
// Copyright (C) 2023-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
//
//
// ***********************************************************************
using System.Linq.Expressions;
using Contracts;
using Microsoft.EntityFrameworkCore;
namespace Repository;
public abstract class RepositoryBase : IRepositoryBase where T : class
{
protected RepositoryContext RepositoryContext;
protected RepositoryBase(RepositoryContext repositoryContext)
=> RepositoryContext = repositoryContext;
public IQueryable FindAll(bool trackChanges) =>
!trackChanges ?
RepositoryContext.Set().AsNoTracking() :
RepositoryContext.Set();
public IQueryable FindByCondition(Expression> expression, bool trackChanges) =>
!trackChanges ?
RepositoryContext.Set() .Where(expression) .AsNoTracking() :
RepositoryContext.Set() .Where(expression);
public void Create(T entity) => RepositoryContext.Set().Add(entity);
public void Update(T entity) => RepositoryContext.Set().Update(entity);
public void Delete(T entity) => RepositoryContext.Set().Remove(entity);
}