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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:49:18+00:00 2026-05-26T08:49:18+00:00

I am using entity framework 4.1, an edmx mapping file is used to generate

  • 0

I am using entity framework 4.1, an edmx mapping file is used to generate poco classes using T4 templates.

How can I get a name of the data base column out of object context for my poco entity properties (if it is possible at all).

I believe the mapping between properties and columns should be in one of the containers:

var container = objectContext.MetadataWorkspace
    .GetEntityContainer(objectContext.DefaultContainerName, DataSpace.CSpace);
...

But I was not able to identify a link between CSpase and SSpace, it looks like CSSpase might do the job, but this container is empty.

Any ideas?

  • 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-26T08:49:19+00:00Added an answer on May 26, 2026 at 8:49 am

    I used a mixed approached to get the mapping information (we have to implement custom data reader/writer for certain types):

    1. First get EntityType object to extract meta information for your POCO type:

      public static EntityType GetEntityTypeForPoco(this ObjectContext context, 
                                                               Type pocoEntityType)
      {
          EntityType entityType 
                   = context.MetadataWorkspace.GetItem<EntityType>
                     (pocoEntityType.FullName, DataSpace.OSpace);
      
          return (EntityType)context.MetadataWorkspace
                 .GetEdmSpaceType((StructuralType)entityType);
      }
      
    2. Read mapping XML document: this part is basically hardcoded, mapping xml document is saved in the assembly where edmx file is, it’s called [your_edmx_file_name].msl

      currentMslSchemaDocument = new StreamReader(
                  Assembly.GetExecutingAssembly().
                  GetManifestResourceStream(CurrentMslSchemaDocumentName)
                ).ReadToEnd();
      
    3. Read property to column mapping from XML document:

      var mappingFragments = MslSchemaDocument
      .Descendants(XName.Get(ElementNameEntityTypeMapping, NamespaceNameMsl))
      .Where(mp => (mp.Attributes(AttributeNameTypeName).Any() 
      && mp.Attribute(AttributeNameTypeName).Value == entityTypeModelName));
      
      if (mappingFragments.Count() == 0)
      {
          throw new Exception(String.Format("Entity mapping {0} is not found in the given schema stream", entityTypeModelName));
      }
      
      //theoretically could be several fragments mapping one entity ytpe to several table
      XElement mappingFragment = mappingFragments.First();
      
      string tableName = mappingFragment.Descendants(XName.Get(ElementNameMappingFragment, NamespaceNameMsl))
      .First().Attribute(AttributeNameStoreEntitySet).Value;
      
      List<KeyValuePair<string, string>> propertyColumnMappingList = new List<KeyValuePair<string, string>>();
      
      foreach (var xScalarProperty in mappingFragment.Descendants(XName.Get(ElementNameScalarProperty, NamespaceNameMsl)))
      {
         propertyColumnMappingList.Add(new KeyValuePair<string, string>(xScalarProperty.Attribute(AttributeNameName).Value,
                  xScalarProperty.Attribute(AttributeNameColumnName).Value));
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Entity Framework, I suddenly get this strange error after publishing my asp.net mvc
I'm using Entity Framework O/R mapper from Microsoft and using entity classes (generated classes
I'm using Entity Framework for creation of my Data Access Layer and I want
I have an ASP.NET Dynamic Data application (using Entity Framework) in which I have
I am putting together a WCF Data Service for PatientEntities using Entity Framework. My
I have several entities generated from my Entity Framework data model. In the .edmx
I'm using the Microsoft.Data.Entity.CTP (in the Entity Framework CTP) under the .NET 4 framework
TLDR; How do I read data from a table using Entity Framework, when the
I am using the entity framework 4 with edmx files and POCOs within an
I am working on an MVC application using Entity Framework. After creating an EDMX,

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.