Change Fluent API mapping dynamically

淺唱寂寞╮ 提交于 2019-11-29 11:31:02

You can add a constructor to your DbContext derivative, having two string arguments for table name and metaschema name. You can store the names in member variables and use them in the ToTable method.

The DbModel is created when it is actually needed, so the constructor always runs before the OnModelCreating event. (This is not always the case in derived classes, but that's a different topic).

As an optimization you can cache compiled DbModels and build DbContexts by the constructor accepting a DbCompiledModel.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!