Introducing Kepler.Core — Smart Field Selection for EF Core APIs
Source: Dev.to
Overview
Kepler.Core is an EF Core extension that lets you improve performance by selecting only the fields you need. It supports flexible filtering, exclusion of sensitive fields, and full visibility into the generated queries.
Key Features
- Selective Field Retrieval – Choose exactly which properties to include in your queries.
- Rich Filtering – Apply any filter type you need (e.g.,
Contains,StartsWith,Equals, etc.). - Sensitive Field Exclusion – Hide fields globally using attributes or the fluent API.
- Global Override – Set
IgnoreGlobalExceptions = trueto bypass all exclusions when required. - Transparent SQL Generation – View the complete lambda expression and the SQL that the NuGet package produces—no black‑box behavior.
- Policy Management – Define multiple named policies per model/table for different use‑cases.
- Introspection Helpers – Inspect global excludes, filters, order‑by fields, and the properties selected by a policy.
Getting Started
-
Add the package
dotnet add package Kepler.Core -
Create a policy in your
Program.cs(or wherever you configure services):services.AddKeplerCore(options => { options.PolicyName = "MyPolicy"; options.IgnoreGlobalExceptions = false; // configure includes, excludes, filters, etc. }); -
Apply the policy when querying:
var result = await dbContext.Customers .ApplyKeplerPolicy("MyPolicy") .ToListAsync();The query will only select the fields defined in MyPolicy and respect any global exclusions.
Multiple Policies
You can define as many policies as needed, each with its own set of included/excluded fields and filters. Reference a policy by name when executing a query.
Useful Links
- NuGet package:
- Source code:
Demo Project
A complete demo using the AdventureWorks 2022 database is available. Clone the repository and run the demo to see Kepler.Core in action:
git clone https://github.com/MohammadAliEbrahimzadeh/Kepler.Core.git
cd Kepler.Core/Demo
dotnet run
Contributing & Feedback
If you find Kepler.Core useful, please ⭐ the repository. For issues, suggestions, or contributions, open an issue or pull request on GitHub. Your feedback is welcome.