Entity Framework 4.1 Dynamically Retrieves Associated Column Name

I am trying to build a SQL statement dynamically.

My context is created dynamically using reflection lookup classes derived from EntityTypeConfiguration and adding them to DbModelBuilder.Configuration.

The My EntityTypeConfiguration classes have the HasColumnName name to map the Entity property name to the db table column name that I need to create my SQL statement.

namespace MyDomain {
    public class TestEntityConfig : EntityTypeConfiguration<TestEntity>{
        Property("Name").HasColumnName("dbName");
    } 
 }

From what I explored, it seems that I can access this information through MetadataWorkspace, through which I can go through the ObjectContext.

I managed to get an object that interests me using MetadataWorkspace.GetItem ("MyDomain.TestEntity", DataSpace.OSpace) that gives me access to properties, but none of the properties properties give me the name of the associated db column, as specified in HasColumnName .

Also, I do not understand what DataSpace.OSpace is and why my model is built in this space.

If anyone can shed light on this, I would be grateful

UPDATE

In addition to the comments by @Ladislav. I found that I can get the information as follows For class properties

ctx.MetadataWorkspace.GetItem<ClrEntityType>("MyDomain.TestEntity", DataSpace.OSpace)).Members

For table properties

ctx.MetadataWorkspace.GetItem<EntityType>("CodeFirstDatabaseSchema.TestEntity",SSpace).Members

, , MyDomain.TestEntity Memeber "". "dbName". , CodeFirstDatabaseSchema, om order, , SSpace, SSpace. -

var memIndex = ctx.MetadataWorkspace.GetItem<ClrEntityType>("MyDomain.TestEntity", DataSpace.OSpace)).Members["Name"].Index;

var dbName = ctx.MetadataWorkspace.GetItem<EntityType>("CodeFirstDatabaseSchema.TestEntity",SSpace).Members[memIndex];
+5
1

MetadataWorkspace contanis , DataSpace. :

  • CSpace - ( )
  • CSSpace - ( , / /)
0

All Articles