none
Find database table name and database column names fpr an Entity RRS feed

  • Question

  • Hello,

    I would like to have a mapping of Entity-Types and the tables they are mapped to. In a second step I want the mapping of the properties of a given EntityType to the database columns of the table.

    For the Entity-side I managed to write

    var mdw = context.ObjectContext().MetadataWorkspace;
    var result = mdw.GetItems<EntityType>(DataSpace.OSpace);
    var obj = result.Single( x => x.Name == "Address" );
    

    and then iterate through obj.Properties.

    For the database side I had no success browsing through the SSpace. I thought

    var sspaceEntitySets = mdw
     .GetItems<EntityContainer>(DataSpace.SSpace).First().BaseEntitySets.OfType<EntitySet>();
          
    var entitySet = sspaceEntitySets.Single( x => x.Name == "Address" );
    
    

    would do it - indeed it does, but only for Entities that are not derived (we have tpt inheritance). So if Address is a derived entity, the statement fails because there is no Address-Entry in the sspaceEntitySets.

    Can anyone pls shed some light on this? How can I find the table names in that case?

    Regards
    daProgramma

    Friday, December 21, 2012 9:59 AM

Answers

All replies

  • Maybe this can be of some help.

    What Tables Are In My EF Model? And My Database?

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alexander Sun Friday, January 4, 2013 8:22 AM
    Saturday, December 22, 2012 3:13 AM
  • Hallo Fernando,

    tnx for the information! It indeed solved important part of the problem.

    Your post has already been marked as "answer" by the moderator.

    Greetings

    daProgramma

    Wednesday, January 9, 2013 10:45 AM
  •   

    Not a problem, glad I was able to help.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, January 9, 2013 2:19 PM