Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7509939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:04:28+00:00 2026-05-29T23:04:28+00:00

I am using a dynamic way of including parent properties when i am retrieving

  • 0

I am using a dynamic way of including “parent properties” when i am retrieving entities from the db. However, since that checks if the property is a value type (or string) or an ienumerable of something (excluding those), it will also include entities that are defined as complextypes. This will lead to an exception.

Is it possible to check if an entity has been defined as a complex type?

Please see this example code:

public IEnumerable<object> LookupExtent(Type type)
{
        var set = Set(type);

        DbQuery q = null;

        foreach (var prop in type.GetParentProperties())
        {
            if (q == null)
                q = set.Include(prop.Name);
            else
                q = q.Include(prop.Name);
        }

        return q.ToObjectArray();
    }

PS: Yes i know this will fail if i have no parent properties…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:04:30+00:00Added an answer on May 29, 2026 at 11:04 pm

    It have much more problems. What happens if your entity contains some additional unmapped properites? You can ask EF to give you names of all mapped navigation properties. It is little science to get information from EF metadata but it is possible. Try something like this (the code expects that you are using DbContext API but it can be easily changed to ObjectContext API):

    ObjectContext objectContext = ((IObjectContextAdapter) dbContext).ObjectContext;
    MetadataWorkspace workspace = objectContext.MetadataWorkspace;
    EntityContainer container = 
        workspace.GetEntityContainer("NameOfYourContextClass", true, DataSpace.CSpace);
    EntitySet entitySet = 
        container.GetEntitySetByName("NameOfYourPropertyExposingDbSetOnTheContext", true);
    IEnumerable<string> navigationPropertyNames = 
        entitySet.ElementType.NavigationProperties.Select(n => n.ToString());
    

    The key is providing correct names into GetEntityContainer and GetEntitySetByName and it is also the main difference between code first and db / model first. If you are using code first these names follows some conventions. If you are using EDMX you can control these names in the designer.

    Anyway this automagic Include is something you should avoid to use. Include only data your really need and do it explicitly to always show the complexity of the query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to store data that is dynamic in nature using
Using C# 2.0 what is the best way to implement dynamic form controls? I
I can do this the proper way using dynamic programming but I can't figure
Without using dynamic SQL, and other than an If ELSE is there any way
I have a program that solves the weighted interval scheduling problem using dynamic programming
I have a number of tables with lots of columns that I'm using Dynamic
I am trying to create a completely dynamic way to query entity framework using
I'm using dynamic LINQ to create a query from given columns the user selects
I am using Dynamic Linq to query our database with a string that is
I'm using jcrop and have written a dynamic way of saving the cropped image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.