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

  • Home
  • SEARCH
  • 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 6948375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:48:53+00:00 2026-05-27T13:48:53+00:00

In either (or all) EF Code-First, EF Model-First, or L2S, is it possible to

  • 0

In either (or all) EF Code-First, EF Model-First, or L2S, is it possible to determine, for example, the name of the originating database table – assuming a one-to-one mapping – given an Entity class, at runtime?

For example, if I have a database with a table called “People”, which I’ve mapped through the aforementioned ORMs to my entity class “Person”, is there a way given respective DataContexts and/or Entity class Type/Instance, to determine the original database table name; “People”?

Obviously, I could do this by adding the metadata to the entities; using a modified T4 Template or custom Attributes for example (similar to how I believe L2S stores the information on the context), but I’m wondering if I can do it out-of-the-box?

Thanks in advance!

EDIT: Ok, I think I’ve found how to do this in Linq 2 Sql, so the question only remains for EF.

// for L2S the Table Name can be retrieved as so...
object[] info = typeof(TSource).GetCustomAttributes(typeof(System.Data.Linq.Mapping.TableAttribute), true); 
String table = (info[0] as System.Data.Linq.Mapping.TableAttribute).Name; 

EDIT: I’m not sure which is better, but it seems you can also get the table name as follows. At a glance, I prefer this second approach, though I’d prefer it more if Mapping.GetTable was Generic – GetTable<TSource>()

// for L2S the Table Name can be retrieved via the Context's mapping as so:
string TableName = context.Mapping.GetTable(typeof(TSource)).TableName;
  • 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-27T13:48:54+00:00Added an answer on May 27, 2026 at 1:48 pm

    The short answer concerning EF: No, it can’t be easily done.

    Extended discussion and possible workarounds: Get Database Table Name from Entity Framework MetaData

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

Sidebar

Related Questions

All the articles I've found via google are either obsolete or contradict one another.
All rows in a table have a type field which is either 0 or
In nearly every model, I end up writing code similar to the below example
I am working with entity framework with code fist design pattern. First of all
Does endianness matter at all with the bitwise operations? Either logical or shifting? I'm
I use EF Code First in my solution with SQL Server Express behind it.
Problem: ^.+ matches only the first line of the source code in dreamweaver. I
Trying to get my first MVC + EF code first project to run. The
I'm using the DbContext and Code First APIs introduced with Entity Framework 4.1. The
I'm currently working on a project which is using EF Code First with POCOs.

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.