All Projects → darxis → Entityframework.lazyloading

darxis / Entityframework.lazyloading

Licence: mit
LazyLoading for EF Core

Projects that are alternatives of or similar to Entityframework.lazyloading

Entityframework.docs
Documentation for Entity Framework Core and Entity Framework 6
Stars: ✭ 888 (+3760.87%)
Mutual labels:  orm, entity-framework, entity-framework-core
Linq2db.entityframeworkcore
Bring power of Linq To DB to Entity Framework Core projects
Stars: ✭ 166 (+621.74%)
Mutual labels:  orm, entity-framework, entity-framework-core
Maikebing.entityframeworkcore.taos
Entity, Framework, EF, Core, Data, O/RM, entity-framework-core,TDengine
Stars: ✭ 113 (+391.3%)
Mutual labels:  orm, entity-framework, entity-framework-core
Pomelo.entityframeworkcore.mysql
Entity Framework Core provider for MySQL and MariaDB built on top of MySqlConnector
Stars: ✭ 2,099 (+9026.09%)
Mutual labels:  orm, entity-framework, entity-framework-core
BlazorEFCoreMultitenant
Examples of multitenancy using EF Core and Blazor.
Stars: ✭ 67 (+191.3%)
Mutual labels:  entity-framework, entity-framework-core
LinqBuilder
LinqBuilder is an advanced implementation of the specification pattern specifically targeting LINQ query generation.
Stars: ✭ 34 (+47.83%)
Mutual labels:  entity-framework, entity-framework-core
EntityFrameworkCore.Triggered
Triggers for EFCore. Respond to changes in your DbContext before and after they are committed to the database.
Stars: ✭ 361 (+1469.57%)
Mutual labels:  entity-framework, entity-framework-core
Efcorepowertools
Entity Framework Core Power Tools - reverse engineering, migrations and model visualization for EF Core
Stars: ✭ 774 (+3265.22%)
Mutual labels:  entity-framework, entity-framework-core
.NET-Core-Learning-Journey
Some of the projects i made when starting to learn .NET Core
Stars: ✭ 37 (+60.87%)
Mutual labels:  entity-framework, entity-framework-core
Gridify
Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
Stars: ✭ 372 (+1517.39%)
Mutual labels:  entity-framework, entity-framework-core
CodexMicroORM
An alternative to ORM's such as Entity Framework, offers light-weight database mapping to your existing CLR objects. Visit "Design Goals" on GitHub to see more rationale and guidance.
Stars: ✭ 32 (+39.13%)
Mutual labels:  entity-framework, entity-framework-core
EntityFrameworkCore.AutoFixture
A library aimed to minimize the boilerplate required to unit-test Entity Framework Core code using AutoFixture and in-memory providers.
Stars: ✭ 31 (+34.78%)
Mutual labels:  entity-framework, entity-framework-core
EFCore.Cassandra
Entity Framework Core provider for Cassandra
Stars: ✭ 23 (+0%)
Mutual labels:  entity-framework, entity-framework-core
Efdesigner
Entity Framework visual design surface and code-first code generation for EF6, Core and beyond
Stars: ✭ 256 (+1013.04%)
Mutual labels:  entity-framework, entity-framework-core
Uno.SQLitePCLRaw.Wasm
An SQLiteRaw WebAssembly provider for SQLitePCLRaw.core
Stars: ✭ 25 (+8.7%)
Mutual labels:  entity-framework, entity-framework-core
Blazor-CRUD
Simple CRUD application using C#/Blazor
Stars: ✭ 25 (+8.7%)
Mutual labels:  entity-framework, entity-framework-core
NETProvider
Firebird ADO.NET Data Provider
Stars: ✭ 113 (+391.3%)
Mutual labels:  entity-framework, entity-framework-core
Entityframeworkcore.cacheable
EntityFrameworkCore second level cache
Stars: ✭ 138 (+500%)
Mutual labels:  orm, entity-framework
Efsecondlevelcache.core
Entity Framework Core Second Level Caching Library
Stars: ✭ 300 (+1204.35%)
Mutual labels:  entity-framework, entity-framework-core
reconciler
Update an entity graph in store to a given one by inserting, updating and removing the respective entities.
Stars: ✭ 24 (+4.35%)
Mutual labels:  entity-framework, entity-framework-core

EntityFramework.LazyLoading Build Status

Lazy Loading for EF Core

Inspired by and partially based on the blog post: https://weblogs.asp.net/ricardoperes/implementing-missing-features-in-entity-framework-core-part-6-lazy-loading

How to enable LazyLoading in EF Core?

Enabling LazyLoading in EF Core is extremely easy with this library. You just need to call UseLazyLoading() (see step 2 below).

However, you will need to slightly modify your entity classes, but just the References, not the Collections (see step 3 below).

Step 1 - Nuget package

Reference the Microsoft.EntityFrameworkCore.LazyLoading NuGet package (https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.LazyLoading/).

Step 2 - Configure the DbContext builder

Call UseLazyLoading() on the DbContextOptionsBuilder when creating the DbContext.

public class MyDbContextFactory : IDbContextFactory<MyDbContext>
{
    private readonly bool _isLazy;

    public MyDbContextFactory (bool isLazy)
    {
        _isLazy = isLazy;
    }

    public MyDbContext Create(DbContextFactoryOptions options)
    {
        var dbContextOptionsBuilder = new DbContextOptionsBuilder<MyDbContext>();
        dbContextOptionsBuilder.UseSqlServer("<some_connection_string>");

        // Here we enable LazyLoading
        dbContextOptionsBuilder.UseLazyLoading();

        return new MyDbContext(dbContextOptionsBuilder.Options);
    }
}

Step 3 - Adjust the model

In your model you need to declare References using the type LazyReference<T>. Collections don't require additional configuration in your model, just use the ICollection<> type.

public class Parent
{
    public ICollection<Child> Childs { get; set; }
}

public class Child
{
    private LazyReference<Parent> _parentLazy = new LazyReference<Parent>();
    public Parent Parent
    {
        get
        {
            return _parentLazy.GetValue(this);
        }
        set
        {
            _parentLazy.SetValue(value);
        }
    }
}

Step 4 - Done!

That's all, LazyLoading enabled! It was so easy, wasn't it?

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].