62 lines
No EOL
2.3 KiB
C#
62 lines
No EOL
2.3 KiB
C#
// ***********************************************************************
|
|
// Assembly : Repository
|
|
// Author : frede
|
|
// Created : 2023 06 10 14:18
|
|
//
|
|
// Last Modified By : frede
|
|
// Last Modified On : 2023 06 10 14:18
|
|
// ***********************************************************************
|
|
// <copyright file="RepositoryBase.cs" company="FCS">
|
|
// 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]
|
|
// </copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using System.Linq.Expressions;
|
|
using Contracts;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Repository;
|
|
|
|
public abstract class RepositoryBase<T> : IRepositoryBase<T> where T : class
|
|
{
|
|
protected RepositoryContext RepositoryContext;
|
|
|
|
|
|
protected RepositoryBase(RepositoryContext repositoryContext)
|
|
=> RepositoryContext = repositoryContext;
|
|
|
|
|
|
public IQueryable<T> FindAll(bool trackChanges) =>
|
|
!trackChanges ?
|
|
RepositoryContext.Set<T>().AsNoTracking() :
|
|
RepositoryContext.Set<T>();
|
|
|
|
|
|
public IQueryable<T> FindByCondition(Expression<Func<T, bool>> expression, bool trackChanges) =>
|
|
!trackChanges ?
|
|
RepositoryContext.Set<T>() .Where(expression) .AsNoTracking() :
|
|
RepositoryContext.Set<T>() .Where(expression);
|
|
|
|
|
|
public void Create(T entity) => RepositoryContext.Set<T>().Add(entity);
|
|
|
|
|
|
public void Update(T entity) => RepositoryContext.Set<T>().Update(entity);
|
|
|
|
|
|
public void Delete(T entity) => RepositoryContext.Set<T>().Remove(entity);
|
|
|
|
} |