Change Fluent API mapping dynamically

前端 未结 1 1631
自闭症患者
自闭症患者 2020-12-19 18:16

Our project uses Entity Framework Code First. We wish to have an instance where a very simple POCO represents many tables in the database. It is part of a horizontal partiti

相关标签:
1条回答
  • 2020-12-19 19: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.

    0 讨论(0)
提交回复
热议问题