YouBIM.Common.Repository.Lib.EntityFramework
2.0.0
See the version list below for details.
dotnet add package YouBIM.Common.Repository.Lib.EntityFramework --version 2.0.0
NuGet\Install-Package YouBIM.Common.Repository.Lib.EntityFramework -Version 2.0.0
<PackageReference Include="YouBIM.Common.Repository.Lib.EntityFramework" Version="2.0.0" />
<PackageVersion Include="YouBIM.Common.Repository.Lib.EntityFramework" Version="2.0.0" />
<PackageReference Include="YouBIM.Common.Repository.Lib.EntityFramework" />
paket add YouBIM.Common.Repository.Lib.EntityFramework --version 2.0.0
#r "nuget: YouBIM.Common.Repository.Lib.EntityFramework, 2.0.0"
#:package YouBIM.Common.Repository.Lib.EntityFramework@2.0.0
#addin nuget:?package=YouBIM.Common.Repository.Lib.EntityFramework&version=2.0.0
#tool nuget:?package=YouBIM.Common.Repository.Lib.EntityFramework&version=2.0.0
YouBIM.Common.Repository.Lib
Description
This repository contains two class libraries that serve as base repositories for Entity Framework Core and MongoDB.
Requirements
.NET Core 6 Entity Framework Core MongoDB
Installation
dotnet restore
Usage
Entity Framework Core
To use the Entity Framework Core base repository, simply inherit from the 'BaseRepository<TEntity>' class.
using YouBIM.Common.Repository.Lib.EntityFramework;
public class UserRepository : BaseRepository<User>
{
public UserRepository(DbContext context) : base(context)
{
}
}
New Methods params
- GetQuery(Expression<Func<TEntity, bool>> filter, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy, params Expression<Func<TEntity, object>>[] includes)
Advanced Usage with includesProperties in V2
You can use the GetQuery method to retrieve a queryable object with filtering, ordering, and eager loading of related entities. Here's an example:
using YouBIM.Common.Repository.Lib.EntityFramework;
using System.Linq.Expressions;
public class UserService
{
private readonly UserRepository _userRepository;
public UserService(UserRepository userRepository)
{
_userRepository = userRepository;
}
public void GetUserDetails()
{
// first option
Expression<Func<User, bool>> filter = user => user.IsActive;
Func<IQueryable<User>, IOrderedQueryable<User>> orderBy = q => q.OrderBy(u => u.LastName);
Expression<Func<User, object>>[] includes = new Expression<Func<User, object>>[]
{
w => w.WorkorderLocations, // Includes
w => w.WorkorderLocations.Select(wl => wl.Location), // Includes nested
w => w.WorkorderLocations.Select(wl => wl.Location.ApplicationConfigsLocations), // Includes nested
w => w.WorkorderLocations.Select(wl => wl.Location.ApplicationConfigsLocations.Select(acl => acl.ApplicationConfig)), // Includes nested
};
var query = _userRepository.GetQuery(filter, orderBy, includes);
//second option
var query2 = _userRepository.GetQuery(
user => user.IsActive, // filter
u => u.LastName, // ordeBy
w => w.WorkorderLocations, // Includes
w => w.WorkorderLocations.Select(wl => wl.Location), // Includes nested
w => w.WorkorderLocations.Select(wl => wl.Location.ApplicationConfigsLocations), // Includes nested
w => w.WorkorderLocations.Select(wl => wl.Location.ApplicationConfigsLocations.Select(acl => acl.ApplicationConfig)), // Includes nested
);
}
}
In this example, we're using the GetQuery method to:
- Filter active users (filter)
- Order them by their last name (orderBy)
- Eagerly load their Address and Orders related entities (includes).
Note: The includes parameter now uses strongly-typed expressions instead of string-based navigation properties, providing better type safety and refactoring support.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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. |
-
net6.0
- Microsoft.EntityFrameworkCore (>= 7.0.20)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.