开发者

Does Entity Framework 4.1 have a meta-model?

In LINQ to SQL you can inspect the underlying meta-model of a data context via its Mapping property.

Is there an equivalent or close-enough pattern in EF Code First for inspecting or manipulating model configuration, given a DbContext instance?

I know you can use the Fluent API to configure the mappings up front, but I'm talking about general in开发者_如何学JAVAspection of a model from outside code using an API, without needing to have object instances to work with (other than the DbContext, of course).


DbContext itself doesn't provide access to meta model. You must convert DbContext to ObjectContext by using:

ObjectContext objectContext = ((IObjectContextAdapter)dbContext).ObjectContext;

After that you can access objectContext.MetadataWorkspace but the workspace itself was not designed for direct usage - API is highly unfriendly and it is read only.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜