YouBIM.Common.Repository.Lib.EntityFramework
9.0.14
dotnet add package YouBIM.Common.Repository.Lib.EntityFramework --version 9.0.14
NuGet\Install-Package YouBIM.Common.Repository.Lib.EntityFramework -Version 9.0.14
<PackageReference Include="YouBIM.Common.Repository.Lib.EntityFramework" Version="9.0.14" />
<PackageVersion Include="YouBIM.Common.Repository.Lib.EntityFramework" Version="9.0.14" />
<PackageReference Include="YouBIM.Common.Repository.Lib.EntityFramework" />
paket add YouBIM.Common.Repository.Lib.EntityFramework --version 9.0.14
#r "nuget: YouBIM.Common.Repository.Lib.EntityFramework, 9.0.14"
#:package YouBIM.Common.Repository.Lib.EntityFramework@9.0.14
#addin nuget:?package=YouBIM.Common.Repository.Lib.EntityFramework&version=9.0.14
#tool nuget:?package=YouBIM.Common.Repository.Lib.EntityFramework&version=9.0.14
YouBIM.Common.Repository.Lib
Description
Base repository abstractions for Entity Framework Core providing standardized data access patterns across YouBIM microservices.
Requirements
- .NET 6/8
- Entity Framework Core
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.
NuGet publishing via pipeline
See the organization guide for building and publishing this library to NuGet via CI:
How to Create and Publish a Nuget Package via Pipeline (Confluence) https://youbimers.atlassian.net/wiki/spaces/YS/pages/2629435399/How+to+Create+and+Publish+a+Nuget+Package+via+Pipeline
| Product | Versions 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 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. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 9.0.14)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.