CommonNetFuncs.EFCore
3.5.0
See the version list below for details.
dotnet add package CommonNetFuncs.EFCore --version 3.5.0
NuGet\Install-Package CommonNetFuncs.EFCore -Version 3.5.0
<PackageReference Include="CommonNetFuncs.EFCore" Version="3.5.0" />
<PackageVersion Include="CommonNetFuncs.EFCore" Version="3.5.0" />
<PackageReference Include="CommonNetFuncs.EFCore" />
paket add CommonNetFuncs.EFCore --version 3.5.0
#r "nuget: CommonNetFuncs.EFCore, 3.5.0"
#:package CommonNetFuncs.EFCore@3.5.0
#addin nuget:?package=CommonNetFuncs.EFCore&version=3.5.0
#tool nuget:?package=CommonNetFuncs.EFCore&version=3.5.0
CommonNetFuncs.EFCore
This project contains helper methods for several common Entity Framework Core operations.
Contents
BaseDbContextActions
Provides a set of generic helper methods for querying and manipulating entities in an EF Core DbContext
. It supports single and composite keys, full graph loading (navigation properties), streaming, projections, filtering, paging, and basic CRUD operations. The class is designed to simplify common data access patterns and reduce boilerplate code. The "Full" parameter / methods indicate loading the full object graph for an entity.
BaseDbContextActions Usage Examples
<details> <summary><h3>Usage Examples</h3></summary>
GetByKey
Retrieves a single entity by its primary key. Supports both full (with navigation properties) and simple queries.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
// Retrieve an entity by its primary key
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
TestEntity? entity = await actions.GetByKey(full: false, primaryKey: 1);
GetAll
Retrieves all entities from the database. Can optionally include navigation properties and control entity tracking.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
// Retrieve all entities, optionally including navigation properties and tracking
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
List<TestEntity>? entities = await actions.GetAll(full: true, trackEntities: false); // Gets all entities without tracking them
GetWithFilter
Retrieves entities matching a specified filter expression. Supports full graph loading and projections.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
// Retrieve entities matching a filter
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
List<TestEntity>? filtered = await actions.GetWithFilter(full: false, whereExpression: x => x.Name == "Target"); // Returns entities where Name == "Target"
GetNavigationWithFilter
Retrieves entities matching a specified filter expression. Supports full graph loading and projections.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
public class TestEntityDetail
{
public int Id { get; set; }
public required string Description { get; set; }
public int TestEntityId { get; set; }
[JsonIgnore]
public TestEntity? TestEntity { get; set; }
}
// Retrieve entities matching a filter
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
Expression<Func<TestEntityDetail, bool>> where = x => x.TestEntityId == 1;
Expression<Func<TestEntityDetail, TestEntity>> select = x => x.TestEntity!;
List<TestEntity>? filtered = await actions.GetNavigationWithFilter(full: false, where, select); // Returns test entity via navigation property on TestEntityDetail
GetWithPagingFilter
Gets entities matching a specified filter expression by pages with the specified skip and page size parameters.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
public sealed class GenericPagingModel<T> where T : class
{
public GenericPagingModel()
{
Entities = [];
}
public List<T> Entities { get; set; }
public int TotalRecords { get; set; }
}
GenericPagingModel<TestEntity> result = await testContext.GetWithPagingFilter(whereExpression: _ => true, selectExpression: x => x, orderByString: nameof(TestEntity.Id), skip: 1, pageSize: 2); // Skips first match and takes 2nd and 3rd record ordered by Id
GetOneWithFilter
Retrieves a single entity matching a filter expression. Returns null if not found.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
// Retrieve a single entity by filter
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
TestEntity? entity = await actions.GetOneWithFilter(x => x.Id == 1); // Returns first entity where Id == 1
GetMaxByOrder
Retrieves the entity with the maximum value for a specified property, optionally filtered.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
// Retrieve the entity with the maximum Id
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
TestEntity? maxEntity = await actions.GetMaxByOrder(full: false, whereExpression: _ => true, descendingOrderEpression: x => x.Id);
GetMinByOrder
Retrieves the entity with the minimum value for a specified property, optionally filtered.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
// Retrieve the entity with the minimum Id
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
TestEntity? minEntity = await actions.GetMinByOrder(_ => true, x => x.Id);
GetMax
Returns the maximum value of a specified property for entities matching a filter.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
// Get the maximum Id value
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
int maxId = await actions.GetMax(_ => true, x => x.Id);
GetMin
Returns the minimum value of a specified property for entities matching a filter.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
// Get the minimum Id value
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
int minId = await actions.GetMin(_ => true, x => x.Id);
GetCount
Returns the count of entities matching a filter.
// Count all entities
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
int count = await actions.GetCount(_ => true);
Create
Adds a new entity to the context.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
// Add a new entity
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
await actions.Create(new TestEntity { Name = "New" });
await actions.SaveChanges();
CreateMany
Adds multiple new entities to the context.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
// Add multiple entities
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
await actions.CreateMany(new List<TestEntity> { new() { Name = "A" }, new() { Name = "B" } });
await actions.SaveChanges();
Update
Updates an existing entity in the context.
public class TestEntity
{
public int Id { get; set; } // Primary key
public required string Name { get; set; }
public DateTime CreatedDate { get; set; }
public ICollection<TestEntityDetail>? Details { get; set; }
}
// Update an entity
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider); entity.Name = "Updated";
actions.Update(entity);
await actions.SaveChanges();
UpdateMany
Updates multiple entities in the context.
// Update multiple entities
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
actions.UpdateMany(entities); // Entities here is multiple changed entities
await actions.SaveChanges();
DeleteByObject
Removes an entity from the context.
// Delete an entity by object
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
actions.DeleteByObject(entity);
await actions.SaveChanges();
DeleteByKey
Removes an entity by its primary key.
// Delete an entity by key
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
bool deleted = await actions.DeleteByKey(entity.Id);
await actions.SaveChanges();
DeleteMany
Removes multiple entities from the context.
// Delete multiple entities
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
actions.DeleteMany(entities);
await actions.SaveChanges();
SaveChanges
Commits all changes made in the context to the database.
// Save changes to the database
BaseDbContextActions<TestEntity, TestDbContext> actions = new(serviceProvider);
bool success = await actions.SaveChanges();
</details>
NavigationProperties
[Description here]
NavigationProperties Usage Examples
<details> <summary><h3>Usage Examples</h3></summary>
IncludeNavigationProperties
[Method Description here]
//Code example here
GetNavigations
[Method Description here]
//Code example here
GetTopLevelNavigations
[Method Description here]
//Code example here
RemoveNavigationProperties
[Method Description here]
//Code example here
</details>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- CommonNetFuncs.Core (>= 3.5.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CommonNetFuncs.EFCore:
Package | Downloads |
---|---|
CommonNetFuncs.Web.Api
Generic API endpoints for use in an ASP.NET API |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
3.6.6 | 0 | 7/21/2025 |
3.6.1 | 140 | 7/14/2025 |
3.6.0 | 157 | 7/14/2025 |
3.5.3 | 142 | 7/10/2025 |
3.5.2 | 142 | 7/9/2025 |
3.5.0 | 145 | 7/7/2025 |
3.4.24 | 102 | 6/27/2025 |
3.4.23 | 132 | 6/26/2025 |
3.4.22 | 133 | 6/26/2025 |
3.4.21 | 128 | 6/26/2025 |
3.4.20 | 155 | 6/25/2025 |
3.4.18 | 152 | 6/23/2025 |
3.4.14 | 155 | 6/17/2025 |
3.4.9 | 302 | 6/11/2025 |
3.4.8 | 289 | 6/11/2025 |
3.4.7 | 286 | 6/10/2025 |
3.4.5 | 247 | 6/9/2025 |
3.4.2 | 162 | 6/2/2025 |
3.4.1 | 100 | 5/30/2025 |
3.4.0 | 153 | 5/30/2025 |
3.3.16 | 144 | 5/28/2025 |
3.3.13 | 146 | 5/20/2025 |
3.3.11 | 139 | 5/19/2025 |
3.3.10 | 273 | 5/13/2025 |
3.3.7 | 220 | 5/12/2025 |
3.3.6 | 153 | 5/8/2025 |
3.3.0 | 178 | 4/29/2025 |
3.2.28 | 207 | 4/10/2025 |
3.2.27 | 175 | 4/8/2025 |
3.2.22 | 210 | 3/12/2025 |
3.2.21 | 172 | 3/11/2025 |
3.2.13 | 199 | 2/13/2025 |
3.2.9 | 139 | 2/4/2025 |
3.2.8 | 111 | 1/31/2025 |
3.2.7 | 125 | 1/28/2025 |
3.2.5 | 109 | 1/27/2025 |
3.2.3 | 136 | 1/17/2025 |
3.2.0 | 121 | 12/19/2024 |
3.1.7 | 108 | 12/18/2024 |
3.1.6 | 125 | 12/17/2024 |
3.1.5 | 96 | 12/16/2024 |
3.1.4 | 110 | 12/13/2024 |
3.1.3 | 91 | 12/13/2024 |
3.1.2 | 90 | 12/13/2024 |
3.1.0 | 165 | 12/6/2024 |
3.0.0 | 135 | 12/3/2024 |
2.1.3 | 118 | 12/3/2024 |
2.1.0 | 110 | 12/2/2024 |
2.0.5 | 128 | 11/26/2024 |
2.0.3 | 115 | 11/18/2024 |
2.0.2 | 114 | 11/18/2024 |
2.0.1 | 120 | 11/15/2024 |
2.0.0 | 113 | 11/14/2024 |
1.0.47 | 130 | 11/14/2024 |
1.0.42 | 156 | 11/12/2024 |
1.0.40 | 140 | 11/12/2024 |
1.0.38 | 114 | 11/7/2024 |
1.0.37 | 145 | 11/4/2024 |
1.0.32 | 117 | 11/1/2024 |
1.0.31 | 123 | 10/31/2024 |
1.0.29 | 116 | 10/29/2024 |
1.0.28 | 127 | 10/25/2024 |
1.0.26 | 169 | 10/18/2024 |
1.0.25 | 108 | 10/17/2024 |
1.0.24 | 100 | 10/17/2024 |
1.0.20 | 113 | 10/14/2024 |
1.0.19 | 129 | 10/11/2024 |
1.0.18 | 126 | 10/11/2024 |
1.0.17 | 129 | 9/27/2024 |
1.0.16 | 118 | 9/27/2024 |
1.0.14 | 119 | 9/23/2024 |
1.0.13 | 134 | 9/18/2024 |
1.0.12 | 132 | 9/18/2024 |
1.0.11 | 122 | 9/18/2024 |
1.0.10 | 161 | 9/11/2024 |
1.0.9 | 149 | 9/11/2024 |
1.0.8 | 144 | 9/11/2024 |
1.0.7 | 144 | 9/11/2024 |
1.0.1 | 151 | 9/4/2024 |
1.0.0 | 144 | 9/2/2024 |