LiteDB.Helper.IncludeAll 0.1.0.3

.NET Standard 2.0
dotnet add package LiteDB.Helper.IncludeAll --version 0.1.0.3
NuGet\Install-Package LiteDB.Helper.IncludeAll -Version 0.1.0.3
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="LiteDB.Helper.IncludeAll" Version="0.1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LiteDB.Helper.IncludeAll --version 0.1.0.3
#r "nuget: LiteDB.Helper.IncludeAll, 0.1.0.3"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install LiteDB.Helper.IncludeAll as a Cake Addin
#addin nuget:?package=LiteDB.Helper.IncludeAll&version=0.1.0.3

// Install LiteDB.Helper.IncludeAll as a Cake Tool
#tool nuget:?package=LiteDB.Helper.IncludeAll&version=0.1.0.3

.IncludeAll() Extension for LiteDB v5

Original author: Chiko
This extension class allows you to .IncludeAll subdocuments referenced in the registered entities in LiteDB v5.

Warning:

This package has not been heavily tested yet. Code may still needs to be polished. Issues and pull requests are welcome.

How to Use

Setting up

Add the package in the project.

dotnet add package LiteDB.Helper.IncludeAll

Import using.

using LiteDB.Helper.IncludeAll;
Register

Register the entities to get included on .IncludeAll() Define which entity shall dereference which subdocument, and with MemberExpression, point out what property should be dereferenced. For example:

LiteDBHelper.Register<Recipe, MaterialInRecipe>(r => r.Materials);

Provide its collection name if the subcollection is using custom collection name. For example:

LiteDBHelper.Register<Recipe, MaterialInRecipe>(r => r.Materials, "materials");

_Note: The Register statement creates the DbRef for you in the global BsonMapper.

Finally, IncludeAll()

The class LiteDBHelper defines an extension method for ILiteCollection<T>, so for any collection, you can, for example

var result = someCollection.IncludeAll().FindAll().ToList();
A short and quick example
using LiteDB;
using Types.TestTypes;

public class Test
{
    public void DoTest()
    {

        LiteDbHelper.Register<Recipe, MaterialInRecipe>(r => r.Materials);
        LiteDbHelper.Register<MaterialInRecipe, Material>(m => m.Material);
        LiteDbHelper.Register<Material, Cost>(m => m.Cost);

        var db = new LiteDatabase("test.db");

        Cost cost = new Cost
        {
            Amount = 20
        };
        var costs = db.GetCollection<Cost>("costs");
        cost.Id = costs.Insert(cost);

        Material material = new Material
        {
            Cost = cost,
            Name = "Mat 01"
        };
        var materials = db.GetCollection<Material>("materials");
        material.Id = materials.Insert(material);

        MaterialInRecipe mInRecipe = new MaterialInRecipe
        {
            Material = material,
            Weight = 500
        };
        var mInRecipes = db.GetCollection<MaterialInRecipe>("materialsInRecipe");
        mInRecipe.Id = mInRecipes.Insert(mInRecipe);

        Recipe recipe = new Recipe
        {
            Materials = new List<MaterialInRecipe> {
                mInRecipe
            },
            Name = "Recipe 01"
        };
        var recipes = db.GetCollection<Recipe>("recipes");
        recipes.Insert(recipe);

        var result = recipes.IncludeAll().FindAll().ToList();
    }
}
Some Tips

Inspect the database using LiteDB.Studio to make sure data stored as references.
Looking for Linux version? Hope this helps.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

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
0.1.0.3 628 10/25/2021
0.1.0.2 197 10/25/2021
0.1.0.1 215 10/25/2021
0.1.0 223 10/25/2021