Is there a way to view Entity Framework First column mappings at runtime?

I am trying to write an add-in for the Entity Framework Code First, and I need a way to get the configuration of the model columns at runtime. For example, this is setting the code on OnModelCreatingwith DbModelBuilder:

builder.Entity<NwdEmployee>()
    .Property(n => n.ReportsToID).HasColumnName("ReportsTo");

Once this is done, EntityFramework knows that my property name is different from the column name in the table, but how can I find that the row "ReportsTo"refers to ReportsToIDitself at runtime? Ideally, I am trying to write a method such as:

public string GetMappedColumnName<TFrom>(DbContext context, 
    Func<TFrom, object> selector);

Which will be used as:

string mappedColumnName = GetMappedColumnName<NwdEmployee>(context, 
    x => x.ReportsToID);

I just don't know where to find the mapped column names in DbContext. Are they available?

+5
1
. , - , , , , .

. , . MetadataWorkspace, , , , . API DbContext. DbContext ObjectContext MetadataWorkspace.

ObjectContext objContext = ((IObjectContextAdapter)dbContext).ObjectContext;
GlobalItem storageMapping = objContext.MetadataWorkspace.GetItem<GlobalItem>("NameOfYourContextClass", DataSpace.CSSpace);

storageMapping System.Data.Mapping.StorageEntityContainerMapping, internal. , MSL = .

, , ( ), , , , 't, .NET framework patch/fix/update .

+4

All Articles