How can i load nested navigation properties using reflection in EF Core Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Entity Framework Core 2.0.1 Eager Loading on all nested related entitiesThenInclude not recognized in EF Core queryEF Core 2.0 include nested entities with dynamic queryHow do you give a C# Auto-Property a default value?How do I use reflection to call a generic method?Set object property using reflectionGet property value from string using reflection in C#How can I generate random alphanumeric strings?How do I remedy the “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning?How to Sort a List<T> by a property in the objectHow to determine if a type implements an interface with C# reflectionHow do I populate current class with new class values?Asp.Net Reflection Count properties

What would you call this weird metallic apparatus that allows you to lift people?

Would color changing eyes affect vision?

Universal covering space of the real projective line?

GDP with Intermediate Production

How can a team of shapeshifters communicate?

Moving a wrapfig vertically to encroach partially on a subsection title

My mentor says to set image to Fine instead of RAW — how is this different from JPG?

How much damage would a cupful of neutron star matter do to the Earth?

Google .dev domain strangely redirects to https

Why is it faster to reheat something than it is to cook it?

Is CEO the "profession" with the most psychopaths?

A proverb that is used to imply that you have unexpectedly faced a big problem

Differences to CCompactSize and CVarInt

License to disallow distribution in closed source software, but allow exceptions made by owner?

Where is the Next Backup Size entry on iOS 12?

Why is std::move not [[nodiscard]] in C++20?

After Sam didn't return home in the end, were he and Al still friends?

Why do early math courses focus on the cross sections of a cone and not on other 3D objects?

Positioning dot before text in math mode

How many time has Arya actually used Needle?

Is there public access to the Meteor Crater in Arizona?

White walkers, cemeteries and wights

Why complex landing gears are used instead of simple,reliability and light weight muscle wire or shape memory alloys?

Is it dangerous to install hacking tools on my private linux machine?



How can i load nested navigation properties using reflection in EF Core



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Entity Framework Core 2.0.1 Eager Loading on all nested related entitiesThenInclude not recognized in EF Core queryEF Core 2.0 include nested entities with dynamic queryHow do you give a C# Auto-Property a default value?How do I use reflection to call a generic method?Set object property using reflectionGet property value from string using reflection in C#How can I generate random alphanumeric strings?How do I remedy the “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning?How to Sort a List<T> by a property in the objectHow to determine if a type implements an interface with C# reflectionHow do I populate current class with new class values?Asp.Net Reflection Count properties



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















This is the code I have written, but I cannot make it work. Does someone have some code for lazy loading nested properties?
i know how to load first level but i ned a second leve to !



example person has many books and a book has one author how can and load all this not only the books ?



public class Lazyloading

public string Include get; set;
public string ThenInclude get; set;


public T Get(Expression<Func<T, bool>> expression, params Lazyloading[] includes)

var query = dbContext.Set<T>().AsQueryable();

if (includes != null)
foreach (var include in includes)
query = query.Include(x => x.GetType().GetProperty(include.Include).GetValue(x)).ThenInclude(it => it.GetType().GetProperty(include.ThenInclude));

return query.FirstOrDefault(expression);










share|improve this question
























  • Possible duplicate of EF Core 2.0 include nested entities with dynamic query

    – GregH
    Mar 22 at 12:18











  • Why do you need to use reflection?

    – Erik Philips
    Mar 22 at 12:29











  • because im using a generic repository and i have oteher layers

    – Wilmar Arias
    Mar 22 at 12:32











  • If you are using string based include's, you don't need ThenInclude because the string can contain the whole include path (dot separated string) - see ThenInclude not recognized in EF Core query. And here Entity Framework Core 2.0.1 Eager Loading on all nested related entities you can see a custom extension method for multiple string includes.

    – Ivan Stoev
    Mar 22 at 17:04

















-1















This is the code I have written, but I cannot make it work. Does someone have some code for lazy loading nested properties?
i know how to load first level but i ned a second leve to !



example person has many books and a book has one author how can and load all this not only the books ?



public class Lazyloading

public string Include get; set;
public string ThenInclude get; set;


public T Get(Expression<Func<T, bool>> expression, params Lazyloading[] includes)

var query = dbContext.Set<T>().AsQueryable();

if (includes != null)
foreach (var include in includes)
query = query.Include(x => x.GetType().GetProperty(include.Include).GetValue(x)).ThenInclude(it => it.GetType().GetProperty(include.ThenInclude));

return query.FirstOrDefault(expression);










share|improve this question
























  • Possible duplicate of EF Core 2.0 include nested entities with dynamic query

    – GregH
    Mar 22 at 12:18











  • Why do you need to use reflection?

    – Erik Philips
    Mar 22 at 12:29











  • because im using a generic repository and i have oteher layers

    – Wilmar Arias
    Mar 22 at 12:32











  • If you are using string based include's, you don't need ThenInclude because the string can contain the whole include path (dot separated string) - see ThenInclude not recognized in EF Core query. And here Entity Framework Core 2.0.1 Eager Loading on all nested related entities you can see a custom extension method for multiple string includes.

    – Ivan Stoev
    Mar 22 at 17:04













-1












-1








-1








This is the code I have written, but I cannot make it work. Does someone have some code for lazy loading nested properties?
i know how to load first level but i ned a second leve to !



example person has many books and a book has one author how can and load all this not only the books ?



public class Lazyloading

public string Include get; set;
public string ThenInclude get; set;


public T Get(Expression<Func<T, bool>> expression, params Lazyloading[] includes)

var query = dbContext.Set<T>().AsQueryable();

if (includes != null)
foreach (var include in includes)
query = query.Include(x => x.GetType().GetProperty(include.Include).GetValue(x)).ThenInclude(it => it.GetType().GetProperty(include.ThenInclude));

return query.FirstOrDefault(expression);










share|improve this question
















This is the code I have written, but I cannot make it work. Does someone have some code for lazy loading nested properties?
i know how to load first level but i ned a second leve to !



example person has many books and a book has one author how can and load all this not only the books ?



public class Lazyloading

public string Include get; set;
public string ThenInclude get; set;


public T Get(Expression<Func<T, bool>> expression, params Lazyloading[] includes)

var query = dbContext.Set<T>().AsQueryable();

if (includes != null)
foreach (var include in includes)
query = query.Include(x => x.GetType().GetProperty(include.Include).GetValue(x)).ThenInclude(it => it.GetType().GetProperty(include.ThenInclude));

return query.FirstOrDefault(expression);







c# ef-core-2.0






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 12:35







Wilmar Arias

















asked Mar 22 at 11:53









Wilmar AriasWilmar Arias

405




405












  • Possible duplicate of EF Core 2.0 include nested entities with dynamic query

    – GregH
    Mar 22 at 12:18











  • Why do you need to use reflection?

    – Erik Philips
    Mar 22 at 12:29











  • because im using a generic repository and i have oteher layers

    – Wilmar Arias
    Mar 22 at 12:32











  • If you are using string based include's, you don't need ThenInclude because the string can contain the whole include path (dot separated string) - see ThenInclude not recognized in EF Core query. And here Entity Framework Core 2.0.1 Eager Loading on all nested related entities you can see a custom extension method for multiple string includes.

    – Ivan Stoev
    Mar 22 at 17:04

















  • Possible duplicate of EF Core 2.0 include nested entities with dynamic query

    – GregH
    Mar 22 at 12:18











  • Why do you need to use reflection?

    – Erik Philips
    Mar 22 at 12:29











  • because im using a generic repository and i have oteher layers

    – Wilmar Arias
    Mar 22 at 12:32











  • If you are using string based include's, you don't need ThenInclude because the string can contain the whole include path (dot separated string) - see ThenInclude not recognized in EF Core query. And here Entity Framework Core 2.0.1 Eager Loading on all nested related entities you can see a custom extension method for multiple string includes.

    – Ivan Stoev
    Mar 22 at 17:04
















Possible duplicate of EF Core 2.0 include nested entities with dynamic query

– GregH
Mar 22 at 12:18





Possible duplicate of EF Core 2.0 include nested entities with dynamic query

– GregH
Mar 22 at 12:18













Why do you need to use reflection?

– Erik Philips
Mar 22 at 12:29





Why do you need to use reflection?

– Erik Philips
Mar 22 at 12:29













because im using a generic repository and i have oteher layers

– Wilmar Arias
Mar 22 at 12:32





because im using a generic repository and i have oteher layers

– Wilmar Arias
Mar 22 at 12:32













If you are using string based include's, you don't need ThenInclude because the string can contain the whole include path (dot separated string) - see ThenInclude not recognized in EF Core query. And here Entity Framework Core 2.0.1 Eager Loading on all nested related entities you can see a custom extension method for multiple string includes.

– Ivan Stoev
Mar 22 at 17:04





If you are using string based include's, you don't need ThenInclude because the string can contain the whole include path (dot separated string) - see ThenInclude not recognized in EF Core query. And here Entity Framework Core 2.0.1 Eager Loading on all nested related entities you can see a custom extension method for multiple string includes.

– Ivan Stoev
Mar 22 at 17:04












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299054%2fhow-can-i-load-nested-navigation-properties-using-reflection-in-ef-core%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299054%2fhow-can-i-load-nested-navigation-properties-using-reflection-in-ef-core%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript