locked
Reading .edmx file programatically RRS feed

  • Question

  • Hi,

    I would like to read .edmx file programatically (C#) to get the actual db table to Entity class mapping.

    I am  basically looking for :

    Given a solution path, Programatically check If any of C# projects of the solution  has a .edmx file, if so read the table to entity class mapping information and write the same to an xml file.

    Now , programatically I am able to traverse through projects of the solution and find out if the .edmx file is present. But I am not able to get the table to entity class mapping information.

    For eg:

    If there is a database named EmployeesMgmt and it has 2 tables : Employees and Department.

    In my C# project, I use Entity designer to create .edmx file.

    Now i would like to know Table-per-concrete class mapping. i.e

    EmployeesMgmt.Employees -> SampleEntityClassProject.Employees

    EmployeesMgmt.Department -> SampleEnittyClassProject.Department.

    Can anyone please help me as to how do i get this information programatically from .edmx file and where is the details stored.

    I also checked manually all three files generated from .edmx file (ssdl, csdl, msl) , none of them have details of the mapped entity class name with complete namespace. 

    Thanks in advance

    Regards,

    Neela

    Tuesday, April 15, 2014 9:35 AM

Answers

  • http://linqtoedmx.codeplex.com/

    I am sure there is code out there use Bing or Google for this. On the other hand, the edmx file is just an XML file, and you should just be able to use Linq-2-XML to read the file.

    • Marked as answer by Fred Bao Friday, April 25, 2014 6:57 AM
    Wednesday, April 16, 2014 5:28 PM

All replies

  • What is all this about? Is this some kind of mapping solution you are trying to come up with where you are trying to map properties to some kind of class/object you created mapping to/from an entity/object?
    Tuesday, April 15, 2014 10:33 AM
  • Hi,

    I am basically trying to get the list of maping of Actual DB Table to Entity class with complete namespace.

    Say,

    - if I have 2 Tables T1 and T2  from Db D1, In my C# class , I use the Entity Desginer and create .edmx file.  With this, there are two entity classes generated  EntityT1 and EntityT2 for DB Tables T1 and T2.

    Now I would like to read through .edmx programatically and get the mapping info like :

    EntityNamespace.EntityT1 is the Enity class for Table D1.T1 and EntityNamespace.EntityT2 is the Entity class for Table D1.T2.

    like :

    <Mappings>

              <Mapping DbEntity="D1.T1" MappedClassEntity="EntityNamespace.EntityT1"/>

               <Mapping DbEntity="D1.T2" MappedClassEntity="EntityNamespace.EntityT2"/>

    </Mappings>

    Thanks in advance



    • Edited by NeelAK Tuesday, April 15, 2014 10:53 AM
    Tuesday, April 15, 2014 10:52 AM
  • Thanks darnold,

    The links which you give me, I believe they give the way to generate the dto objects from the database and map the database to dto/class entities.

    But my requirement is not to generate , but just to read the mappings of class to table which are achieved from Entity Data model.

    Wednesday, April 16, 2014 8:48 AM
  • http://linqtoedmx.codeplex.com/

    I am sure there is code out there use Bing or Google for this. On the other hand, the edmx file is just an XML file, and you should just be able to use Linq-2-XML to read the file.

    • Marked as answer by Fred Bao Friday, April 25, 2014 6:57 AM
    Wednesday, April 16, 2014 5:28 PM