0

I need to know information about entities, tables, mappings, keys etc for the given instance of DbContext. In Entity Framework 6 I was writing edmx like this:

System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(dbContext, xmlWriter);

which I then used to build my own data model (this is needed for a tool which supports loading data from different sources). How do I get such information for the new EF Core (previous EF 7)? I could use Reflection, but this will give me only the conceptual schema, while I also need mappings and storage schema. I've been looking through the EF source code for a while now, but don't seem to find any object, that stores all the required data.

1 Answer 1

2

This should get you started

using (var ctx = new TestContext())
{
    var entityType = ctx.Model.FindEntityType(typeof (Entity_Basic));
    var tableName = entityType.SqlServer().TableName;
    var columnName = entityType.GetProperties().ToList()[0].SqlServer().ColumnName;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.