ByteDecoder.Queryology 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ByteDecoder.Queryology --version 1.0.0                
NuGet\Install-Package ByteDecoder.Queryology -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ByteDecoder.Queryology" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ByteDecoder.Queryology --version 1.0.0                
#r "nuget: ByteDecoder.Queryology, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ByteDecoder.Queryology as a Cake Addin
#addin nuget:?package=ByteDecoder.Queryology&version=1.0.0

// Install ByteDecoder.Queryology as a Cake Tool
#tool nuget:?package=ByteDecoder.Queryology&version=1.0.0                

Queryology

CI Maintainability Test Coverage

You can find the documentation for previous versions < 1.0.0 here DOCUMENTATION_UNTIL_0.4.3.md

Minimalist query engine executor used with Entity Framework Core + LINQ for quick experiments

Targeted to .Net Core 3.1

Installation

Install the Queryology NuGet Package.

Package Manager Console

Install-Package ByteDecoder.Queryology
Install-Package ByteDecoder.Queryology.Providers.ObjectDumper

.NET Core CLI

dotnet add package ByteDecoder.Queryology
dotnet add package ByteDecoder.Queryology.Providers.ObjectDumper

Examples and usage

If 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:

  • Queryology NuGet package installed and Object Dumper provider
  • Your EF Core DbContext class, or if you want to use only LINQ to Objects, Queryology provides a default NullDbContext to avoid setting one by yourself
  • Have a query class per each one of your experiments
  • Inherit and implement QueryBase<T> where T is the type of your EF Core DbContext class
  • QueryBase<T> Uses an ObjectDumper as provider from Microsoft for exploring your Linq results
  • Don't forget to add a logger in your EF Core DbContext class to analyze the SQL output
  • Just call an instance of QueryologyEngine with your EF Core DbContext class and, it will find for you all your query classes that inherit from QueryBase<T> and it will execute them
  • Enjoy

QueryBase<T> Provides you:

  • DataContext property which holds the reference to the provided EF Core DbContext class
  • DisplayData method to write in the console the structure of your query result using the Data property
  • Data property defined as dynamic since you can project anonymous types with LINQ
  • Executable property that is overridable to set to false if you do not want this rule to be executed by QueryologyEngine

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 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.Example.Models;
using ByteDecoder.Queryology.Providers.ObjectDumper;
using System;

class Program
{
  static void Main(string[] args)
  {
    using var dbContext = new MyDbCoreContext();
    var totalQueries = new QueryologyEngineBuilder<MyDbCoreContext>()
        .AddObjectDumper(dbContext)
        .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 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.Example.Models;
using ByteDecoder.Queryology.Providers.ObjectDumper;
using System;

class Program
{
  static void Main(string[] args)
  {
    using var nullDbContext = new NullDbContext();
    var totalQueries = new QueryologyEngineBuilder<NullDbContext>()
        .AddObjectDumper(nullDbContext)
        .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 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>()
                            .AddObjectDumper(nullDbContext)
                            .Build();
var totalQueries = queryologyEngine
                    .IgnoreExcludedQueries(false)
                    .Execute();

That is all, you can continue adding more queries and do not bother about the infrastructure

Running Example .Net Core Console App

First create the example database and apply the migrations with:

cd ./src
dotnet ef database update -p ./Queryology.Example

Then run the example console project:

cd Queryology.Example/
dotnet run

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ByteDecoder/Queryology.

Copyright (c) 2020 Rodrigo Reyes released under the MIT license

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.0 545 7/30/2020
1.2.0 476 7/29/2020
1.1.1 496 7/29/2020
1.1.0 509 7/22/2020
1.0.0 448 7/21/2020
0.4.3 493 7/13/2020
0.4.2 498 7/13/2020
0.4.1 439 7/7/2020
0.4.0 556 7/4/2020
0.3.0 515 7/4/2020
0.2.1 411 7/3/2020
0.1.0 447 7/2/2020