Performing projections on multiple databases with only one dbContext

后端 未结 3 928
孤街浪徒
孤街浪徒 2021-01-24 23:00

We are using EF.Core for a current project. The project has three databases which is a real nuisance that can\'t really be avoided. The databases have the same structure. So we

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-24 23:39

    Interesting problem.

    One context cannot across multiple database,

    using multiple context will end up loading data in memory and doing linq to objects which perhaps is not desired or even possible.

    First option is to use linked tables in database and query against it. which I think is the easiest.

    I don't know how complex is your query and how big is data to suggest a in memory scenario, based on what you are doing in your query you may have some ad hoc solutions , examples:

    • you may implement some enumerators that load data from one database by a specific order that is needed for efficient in memory process, then you can combine them in one and use it.
    • if your query is more about joins on big data, you have to break it, create objects with minimum number of columns project to them and implement the query based on that, further you can use this query results in other queries with will load the missing columns.

提交回复
热议问题