Bat.EntityFrameworkCore 10.0.0

dotnet add package Bat.EntityFrameworkCore --version 10.0.0
                    
NuGet\Install-Package Bat.EntityFrameworkCore -Version 10.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bat.EntityFrameworkCore" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bat.EntityFrameworkCore" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Bat.EntityFrameworkCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bat.EntityFrameworkCore --version 10.0.0
                    
#r "nuget: Bat.EntityFrameworkCore, 10.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bat.EntityFrameworkCore@10.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bat.EntityFrameworkCore&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Bat.EntityFrameworkCore&version=10.0.0
                    
Install as a Cake Tool

For use Bat.EntityFrameworkCore just do it :

1- Install Bat.EntityFrameworkCore on your project

2- Register IEFGenericRepo<TEntity> to service container for example :

builder.Services.AddTransient<IEFGenericRepo<User>, EFGenericRepo<User>>();
builder.Services.AddTransient<IEFGenericRepo<Address>, EFGenericRepo<Address>>();

builder.Services.AddScoped<AppUnitOfWork>();

3- Use it in bussiness logic for example :

// Create DbContext
public class AppDbContext : BatDbContext
{
    public AppDbContext() { }

    public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        builder.ApplyConfigurationsFromAssembly(typeof(AppUnitOfWork).Assembly);

        base.OnModelCreating(builder);
    }

    public DbSet<User> Users { get; set; }
    public DbSet<Address> Addresses { get; set; }

}


// Create UnitOfWork
public class AppUnitOfWork : IBatUnitOfWork
{
    private readonly AppDbContext _appDbContext;
    private readonly IServiceProvider _serviceProvider;

    public AppUnitOfWork(AppDbContext appDbContext, IServiceProvider serviceProvider)
    {
        _appDbContext = appDbContext;
        _serviceProvider = serviceProvider;
    }

    public EFGenericRepo<User> UserRepo => (EFGenericRepo<User>)_serviceProvider.GetRequiredService<IEFGenericRepo<User>>();
    public EFGenericRepo<Address> AddressRepo => (EFGenericRepo<Address>)_serviceProvider.GetRequiredService<IEFGenericRepo<Address>>();

    
    public DatabaseFacade Database { get => _appDbContext.Database; }
    public ChangeTracker ChangeTracker { get => _appDbContext.ChangeTracker; }


    public EFGenericRepo<T> GetRepository<T>() where T : class, IBaseEntity
        => EFGenericRepo<T>)_serviceProvider.GetRequiredService<IEFGenericRepo<T>>();

    public async Task<IEnumerable<T>> ExecuteProcedure<T>(string sqlQuery, params object[] parameter) where T : class
        => await _appDbContext.ExecuteProcedure<T>(sqlQuery, parameter);


    public Task<SaveChangeResult> BatSaveChangesAsync(CancellationToken cancellationToken = default)
        => _appDbContext.BatSaveChangesAsync(cancellationToken);


    public void Dispose()
    {
        _appDbContext.Dispose();

        GC.SuppressFinalize(this);
    }
}


// Use power Off EFGenericRepo
public class UserService : IUserService
{
    private readonly AppUnitOfWork _appUow;

    public UserService(AppUnitOfWork appUnitOfWork)
    {
        _appUow = appUnitOfWork;
    }

    public async Task ExecuteSample()
    {
        var x0 = await _appUow.GetRepository<User>().AnyAsync();

        var x1 = await _appUow.AddressRepo.CountAsync();
        var x2 = await _appUow.UserRepo
            .Include(x => x.Families)
            .Select(x => new GetUserDto { UserId = x.UserId, Name = x.Name, Families = x.Families })
            .FirstOrDefaultAsync(x => x.UserId > 1);

        var xxx1 = await _appUow.UserRepo
            .Where(x => x.UserId > 1).ToListAsync();

        var xxx2 = await _appUow.UserRepo
            .Include(x => x.Families).ToListAsync();

        var xxx3 = await _appUow.UserRepo
            .Where(x => x.UserId > 1)
            .Include(x => x.Families.Where(x => x.FamilyId > 0))
            .ThenInclude(x => x.Addresses)
            .OrderByDescending(x => x.UserId)
            .ToListAsync();

        var xxx4 = await _appUow.UserRepo
            .Select(x => new { x.UserId, x.Name }).ToListAsync();

        var xxx5 = await _appUow.UserRepo
            .Include(x => x.Families)
            .Select(x => new { x.UserId, x.Name, x.Families }).ToListAsync();

        var xxx6 = await _appUow.UserRepo
            .Include(x => x.Families)
            .Where(x => x.UserId > 1)
            .Select(x => new { x.UserId, x.Name, x.Families }).ToListAsync();

        var xxx7 = await _appUow.UserRepo
            .Include(x => x.Families)
            .ThenInclude(x => x.Addresses)
            .OrderByDescending(x => x.UserId)
            .Select(x => new { x.UserId, x.Name, x.Families })
            .FirstOrDefaultAsync();

        var xxx8 = await _appUow.UserRepo.AsNoTracking().FirstOrDefaultAsync(x => x.UserId > 1);

        var xxx9 = await _appUow.UserRepo.OrderBy(x => x.UserId).FirstOrDefaultAsync(x => x.UserId > 1);

        var xxx10 = await _appUow.UserRepo.Where(x => x.UserId > 1).ToPagingListDetailsAsync(pagingParameter);
        var xxx11 = await _appUow.UserRepo.Include(x => x.Families).Where(x => x.UserId > 1).ToPagingListDetailsAsync(pagingParameter);
        var xxx12 = await _appUow.UserRepo.Select(x => new { x.UserId, x.Name }).OrderByDescending(x => x.UserId).ToPagingListDetailsAsync(pagingParameter);

        var xxx13 = await _appUow.UserRepo.AnyAsync(x => x.UserId > 1);
        var xxx14 = await _appUow.UserRepo.Include(x => x.Families).AnyAsync();
        var xxx15 = await _appUow.UserRepo.Include(x => x.Families).AnyAsync(x => x.UserId > 1);

        var xxx16 = await _appUow.UserRepo.CountAsync();
        var xxx17 = await _appUow.UserRepo.Include(x => x.Families).CountAsync();
        var xxx18 = await _appUow.UserRepo.Include(x => x.Families).CountAsync(x => x.UserId > 1);



        var user0 = await _appUow.UserRepo.FirstOrDefaultAsync(
            new QueryFilterWithSelector<User, int>
            {
                Conditions = x => x.UserId > 0,
                ThenIncludeProperties = a => a.Include(a => a.Families).ThenInclude(a => a.Addresses),
                Selector = x => x.UserId
            });

        var user00 = await _appUow.UserRepo.FirstOrDefaultAsync(
            new QueryFilterWithSelector<User, string>
            {
                Conditions = x => x.UserId > 0,
                ThenIncludeProperties = a => a.Include(a => a.Families).ThenInclude(a => a.Addresses),
                Selector = x => x.Name
            });

        var user001 = await _appUow.UserRepo.FirstOrDefaultAsync(
            new QueryFilter<User>
            {
                Conditions = x => x.UserId > 1,
                ThenIncludeProperties = a => a.Include(a => a.Families).ThenInclude(a => a.Addresses),
            });

        var user002 = await _appUow.UserRepo.GetPagingAsync(
            new QueryFilter<User>
            {
                Conditions = x => x.UserId > 0,
                PagingParameter = new PagingParameter(2, 2),
                ThenIncludeProperties = a => a.Include(a => a.Families).ThenInclude(a => a.Addresses)
            });


        var user003 = await _appUow.UserRepo.GetAsync(
            new QueryFilter<User>
            {
                Conditions = x => x.UserId > 0,
                ThenIncludeProperties = a => a.Include(a => a.Families).ThenInclude(a => a.Addresses)
            });


        var query = "EXEC [Auth].[GetUserMenu] @UserId, @Type";
        var userMenu = await _appUow.ExecuteProcedure<MenuModel>(query, 
            new SqlParameter("@UserId", userId), 
            new SqlParameter("@Type", RoleType.Online));

    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Bat.EntityFrameworkCore:

Package Downloads
Bat.EntityFrameworkCore.Tools

For Contact Me Please Send Mail Or Call To : Tel : +989301919109 Mail : mehrannoruzi@gmail.com

Bat.Test

For Contact Me Please Send Mail Or Call To : Tel : +989301919109 Mail : mehrannoruzi@gmail.com

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0 39 12/24/2025
8.0.19 340 8/5/2025
8.0.18 187 7/29/2025
8.0.11 337 11/26/2024
8.0.1 643 1/22/2024
8.0.0 316 12/1/2023
7.0.3 629 2/28/2023
7.0.2 617 2/4/2023
7.0.0 584 12/6/2022
6.0.22 370 8/21/2023
6.0.21 351 8/19/2023
6.0.1 1,204 3/27/2022
1.1.3 1,491 12/26/2021
1.1.2 964 7/12/2021
1.1.1 959 4/14/2021
1.1.0 958 3/26/2021
1.0.8 901 2/7/2021
1.0.7 852 2/4/2021
1.0.6 873 1/30/2021
1.0.5 685 10/27/2020
1.0.4 1,272 10/20/2020

- Upgrade to net10.0 and C#14.0
- Upgrade to EF10.x
- Add new Repository Extension methods