| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
You can find the documentation for previous versions < 1.0.0 here documentation until v0.4.3 here
Minimalist query engine executor used with Entity Framework Core + LINQ for quick experiments
Targeted to .Net 8
Install the Queryology NuGet Package.
Install-Package ByteDecoder.Queryology
Install-Package ByteDecoder.Queryology.Providers.ObjectDumper
dotnet add package ByteDecoder.Queryology
dotnet add package ByteDecoder.Queryology.Providers.ObjectDumperIf you are exploring a query or learning Entity Framework core, and want to analyze, understand, and doing some experiments, but you do not want to spend a lot of time doing boilerplate infrastructure. Enter the Queryology Engine.
By using it, allow you to stay focus reviewing and writing your queries, executing them, and you can disable them for not execution in runtime with the minimal code changes.
The basic theory that you need:
QueryBase<T> Provides you:
Minimalist EF Core DbContext example code:
// Create your EF Core DbContext class
public class MyDbCoreContext : DbContext { ... }
// Write your query class(es) and inherit from QueryBase<T> where T
// is your EF Core DbContext class
public class MyQuery : QueryBase<MyDbCoreContext>
{
public MyQuery(MyDbCoreContext dbContext, DisplayObjectData objectDisplayer)
: base(dataContext, objectDisplayer) { }
public override void Execute()
{
Data = DataContext.Books
.Include(b => b.AuthorsLink)
.ThenInclude(a => a.Author)
.Include(b => b.Reviews)
.Include(b => b.Promotion)
.First();
DisplayData($"{typeof(MyQuery)} query results:", 3);
}
}
// In your .Net Core application, instantiate the engine and execute it!
using ByteDecoder.Queryology;
using ByteDecoder.Queryology.Providers.ObjectDumper;
class Program
{
static void Main(string[] args)
{
using var dbContext = new MyDbCoreContext();
var totalQueries = new QueryologyEngineBuilder<EfCoreContext>()
.Configure(options => options.DataContextProvider = dbContext)
.AddObjectDumper()
.Build()
.Execute();
Console.WriteLine($"\n🦄🦄 Total Queries allowed to be executed: {totalQueries}");
Console.WriteLine("🐵🐵 Press Enter to continue... 🐵🐵");
Console.ReadLine();
}
}Minimalist EF Core only with LINQ to Objects example code:
// Write your query class(es) and inherit from QueryBase<T> and use NullDbContext
// as your type T
public class LinqToObjectsQuery : QueryBase<NullDbContext>
{
public LinqToObjectsQuery(NullDbContext dbContext, DisplayObjectData objectDisplayer)
: base(dataContext, objectDisplayer) { }
public override void Execute()
{
Console.WriteLine("Some LINQ to Objects code here");
}
}
// In your .Net Core application, instantiate the engine and execute it!
using ByteDecoder.Queryology;
using ByteDecoder.Queryology.Providers.ObjectDumper;
class Program
{
static void Main(string[] args)
{
using var nullDbContext = new NullDbContext();
totalQueries = new QueryologyEngineBuilder<NullDbContext>()
.Configure(options => options.DataContextProvider = nullDbContext)
.AddObjectDumper()
.Build()
.Execute();
Console.WriteLine($"\n🦄🦄 Total Queries allowed to be executed: {totalQueries}");
Console.WriteLine("🐵🐵 Press Enter to continue... 🐵🐵");
Console.ReadLine();
}
}Mark a Query class to be ignored and not to be executed at runtime:
// Just override the Executable property; and set it to false.
public class NeverAgainQuery : QueryBase<MyDbCoreContext>
{
public NeverAgainQuery(EfCoreContext dbContext, DisplayObjectData objectDisplayer)
: base(dataContext, objectDisplayer) { }
public override bool Executable => false;
public override void Execute()
{
Console.WriteLine("Never again.. I will never get executwed by QueryologyEngine =(");
throw new NotImplementedException();
}
}Ignore excluded queries and execute all queries under type T
// Changing the default value of *IgnoreExcludedQueries* resets to its true default value
// after the engine completes all the query processing
using var nullDbContext = new NullDbContext();
var queryologyEngine = new QueryologyEngineBuilder<NullDbContext>()
.Configure(options => options.DataContextProvider = nullDbContext)
.AddObjectDumper()
.Build();
var totalQueries = queryologyEngine
.IgnoreExcludedQueries(false)
.Execute();That is all, you can continue adding more queries and do not bother about the infrastructure
First create the example database and apply the migrations with:
cd ./src
dotnet ef database update -p ./Queryology.ExampleThen run the example console project:
cd Queryology.Example/
dotnet runBug reports and pull requests are welcome on GitHub at https://github.com/ByteDecoder/Queryology.
Copyright (c) 2020 Rodrigo Reyes released under the MIT license
| Back | FazBrowse Home | New Git URL |