Coder Social home page Coder Social logo

entityframework.include's Introduction

EntityFramework.Include

A library that extends Include of Entity Framework to provide filtering navigation property.

Required EntityFramework version is 6.1.3.

##Download EntityFramework.Include is available on nuget.org -> EntityFramework.Include

To install EntityFramework.Include, run the following command in Package Manager Console.

PM> Install-Package EntityFramework.Include

##Usage

//Required using EntityFramework.Include.Extensions

//Example Entity...
public class Parent
{
    public int Id { get; set; }

    public int Age { get; set; }
    
    [NotMapped]
    public int ChildrenCount { get; set; }

    public List<Child> Children { get; set; } = new List<Child>();
}

public class Child
{
    public int Id { get; set; }

    public int Age { get; set; }
}

//In code...
var list = context.ParentSet.Include(p => p.Children, p => p.Children.Take(10).ToList())
                            .Include(p => P.ChildrenCount, p => p.Children.Count)
                            .ToListWithInclude();

Console.WriteLine(list.First().Children.Count); //10
Console.WriteLine(list.First().ChildrenCount); //output all Children count

To retrieve as List or T[], use ToListWithInclude/Aysnc or ToArrayWithInclude/Aysnc

var list = context.ParentSet.Include(p => p.Children, p => p.Children.Take(10).ToList())
                            .Include(p => P.ChildrenCount, p => p.Children.Count)
                            .ToListWithInclude();
                            
var array = context.ParentSet.Include(p => p.Children, p => p.Children.Take(10).ToList())
                            .Include(p => P.ChildrenCount, p => p.Children.Count)
                            .ToArrayWithInclude();

If include same property, the last include will be preferred

var list = context.ParentSet.Include(p => p.Children, p => p.Children.Take(10).ToList())
                            .Include(p => p.Children, p => p.Children.Take(20).ToList()) //duplicate
                            .Include(p => P.ChildrenCount, p => p.Children.Count)
                            .ToListWithInclude();
                            
Console.WriteLine(list.First().Children.Count); //20

##Notice

You can't use default Include of Entity Framework now.

var list = context.ParentSet.Include(p => p.Children) //Doesn't work now.
                            .Include(p => P.ChildrenCount, p => p.Children.Count)
                            .ToListWithInclude();

So describe like this

var list = context.ParentSet.Include(p => p.Children, p => p.Children) //This works.
                            .Include(p => P.ChildrenCount, p => p.Children.Count)
                            .ToListWithInclude();

entityframework.include's People

Contributors

deyunote avatar a-r-g-v avatar

Watchers

Costas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.