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 6824889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:57:20+00:00 2026-05-26T21:57:20+00:00

I have a challenging problem where I would like to use reflection on my

  • 0

I have a challenging problem where I would like to use reflection on my Entity Framework mapping to find all the foreign keys that reference a table, and I want the names of the columns that are the foreign keys.

According to another post on SO, I can easily find the navigation properties on a table through reflection. But this doesn’t give me the name of the property or column that contains the foreign key value.

The reason I’m trying to do this is that I have a large number of tables (nearly 40) that reference one table of items. Let’s say a user enters a new value in the items table called “Andew” and later an admin notices it’s actually just a typo for the already-existing item “Andrew”. Now I want to find all references to “Andew” and change those references to “Andrew”. I would prefer to do this effeciently, so using the reverse-navigation properties would be too slow since you have to load the values before modifying them. What I would like to do is be able to reflect a list of tables and columns, then issue update commands directly to the database. It would look something like this:

var command = String.Format("UPDATE [{0}] SET [{1}] = {{1}} WHERE [{1}] = {{0}}; ", fk.FromTableName, fk.FromColumnName);
dataContext.ExecuteStoreCommand(command, new Object[] { oldID, newID });

In LINQ to SQL this was actually pretty easy… 20 lines of reflection on the LINQ auto-generated code and I was done, but we switched to EF recently and I can’t find the names of the foreign key columns through EF.

A simplified example of what I’m looking for: if I have an object called Employee with a navigation property called Manager and a foreign key of ManagerID, then I want to know that Manager is my navigation property and the underlying storage is the ManagerID property. I want to do this strictly through reflection or metadata so I can build a dynmaic query from it.

  • 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-26T21:57:20+00:00Added an answer on May 26, 2026 at 9:57 pm

    The answer to the question is in another post here: Read foreign key metadata programatically with Entity Framework 4

    Note the poster’s answer didn’t work for me. Use @Ashraf’s answer, which worked great.

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

Sidebar

Related Questions

I have a regex 'simple' that I'd like to use as a building block
I have a class that keeps data stores/access data by using words.separated.by.dots keys and
I thought that I could use SimpleDB to take care of the most challenging
Hi friends hope all r doing well. I have a problem while reading xml
I have a challenging problem I've been battling for some time now. The Problem:
I have a challenging question. My requirement is like i have a xml file
I have a large and challenging C++ project that I plan to undertake, one
I have a bit of a challenging problem. I'm using the Blogger JSON API
While clensing PII from test data I have been stuck with a challenging scenario:
NOTE: This is a challenging problem for anybody who likes logic problems, etc. Consider

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.