Entity Framework - how do I get the columns?

后端 未结 7 1548
后悔当初
后悔当初 2020-12-01 14:25

I wish to get a list of columns names, types and whether the column is a PK of a table object in Entity Framework.

How do I do this in C# (4.0) (ideally generically)

7条回答
  •  清歌不尽
    2020-12-01 14:51

    If you're using DB First or Model First, open up the .edmx file EF generated in a text editor. It's just an XML file, and it contains everything you need. Here's an example from a model of mine. Note that I'm using Oracle's EF driver, so yours won't look identical (but it should be pretty close).

            
              
                
              
              
              
              
              
              
              
              
              
              
              
              
              
              
              
              
              
            
    

    You can use an XML parser to parse the file and get what you need. The .edmx file contains data on both the entities and the SQL tables, so you'll need to make sure you're getting the right part of it to get what you want.

提交回复
热议问题