0

I am creating a Three-Tier Architecture Demo .NET Project. While I was creating my layers, I was faced with that error.

Severity Code Description Project File Line Suppression State Error CS0060 Inconsistent accessibility: base class 'EfEntityRepositoryBase<Product, NorthwindContext>' is less accessible than class 'EfProductDal' DataAccess C:\Users\90553\source\repos\kodlamaio_bootcamp\MyFinalProject\DataAccess\Concrete\EntityFramework\EfProductDal.cs 13 Active

EfProductDal.cs:

using Core.DataAccess.EntityFramework;
using DataAccess.Abstract;
using Entities.Concrete;


namespace DataAccess.Concrete.EntityFramework
{
    public class EfProductDal : EfEntityRepositoryBase<Product, NorthwindContext>, IProductDal
    {
        
    }
}

EfEntityRepositoryBase.cs:

using Core.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Core.DataAccess.EntityFramework
{
    public class EfEntityRepositoryBase<TEntity, TContext> : IEntityRepository<TEntity>
        // Give constraints
        where TEntity : class, IEntity, new()
        where TContext : DbContext, new()
    {
        public void Add(TEntity entity)
        {
            // IDisposable pattern implementation of c#
            // if program done with NorthwindContext, context is collected by garbage collector 
            using (TContext context = new TContext())
            {
                // create relation between references
                var addedEntity = context.Entry(entity);
                addedEntity.State = EntityState.Added;
                context.SaveChanges();
            }
        }

        public void Delete(TEntity entity)
        {
            using (TContext context = new TContext())
            {
                // create relation between references
                var deletedEntity = context.Entry(entity);
                deletedEntity.State = EntityState.Deleted;
                context.SaveChanges();
            }
        }

        public TEntity Get(Expression<Func<TEntity, bool>> filter)
        {
            using (TContext context = new TContext())
            {
                return context.Set<TEntity>().SingleOrDefault(filter);
            }
        }


        public List<TEntity> GetAll(Expression<Func<TEntity, bool>> filter = null)
        {
            using (TContext context = new TContext())
            {
                return filter == null
                    ? context.Set<TEntity>().ToList()
                    : context.Set<TEntity>().Where(filter).ToList();
            }

        }

        public void Update(TEntity entity)
        {
            using (TContext context = new TContext())
            {
                var updatedEntity = context.Entry(entity);
                updatedEntity.State = EntityState.Modified;
                context.SaveChanges();
            }
        }
    }
}

IEntityRepository.cs:

using Core.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Core.DataAccess
{
    // Generic Constraint
    // class: reference type
    // IEntity: It can be IEntity or any object that implements IEntity
    // new(): must be object that can used with new
    public interface IEntityRepository<T> where T:class,IEntity,new()
    {

        List<T> GetAll(Expression<Func<T,bool>> filter=null);

        T Get(Expression<Func<T,bool>> filter);
        void Add(T entity);

        void Update(T entity);

        void Delete(T entity);

    }
}

Solution Explorer Image:

Solution Explorer Image

Despite all my classes being public why visual studio gives an error about less accessibility. Any Help?

0 Answers0