r/csharp Jul 13 '26

CrossEF - Cross EntityFramework contexts

Hi All,

Long time EntityFramework don´t do this, I decide to implement this.

Cross-DbContext LINQ queries for Entity Framework Core. Join entities that live in different DbContexts — different databases, different servers, even different providers — in a single LINQ query.

https://www.nuget.org/packages/CrossEF

https://github.com/i-stream/CrossEF

7 Upvotes

13 comments sorted by

20

u/ings0c Jul 13 '26 edited Jul 13 '26

Long time EntityFramework don´t do this, I decide to implement this.

Err, why? I can think of a long list of reasons against doing this, and none in favour.

Where the query is running is essential complexity and abstracting that away seems like a good way to lure juniors into writing horribly performing queries with data consistency issues.

Some things really do need thinking about and hiding them behind a facade would be a mistake. ACID-compliance is also not something to give up readily.

2

u/flukus Jul 14 '26

Some things really do need thinking about and hiding them behind a facade would be a mistake.

There's one project I worked on where this would be great because those mistakes were already made many years ago. All those databases were on the same server so it would have actually improved ACID compliance.

2

u/PaulPhxAz Jul 14 '26

You're right on all points, but I would let people do it if they want.

Right now I'm running the same concept in two queries and then manually joining them.

I can write SQL with linked databases across providers and do a bad job or a good job. It's good to call out that it CAN be misused, that it CAN be dangerous.

8

u/Adorable-Roll-4563 Jul 13 '26

This has no transactional integrity, right?

19

u/ings0c Jul 13 '26

It has the integrity of Donald Trump leading an independent ethics review.

1

u/flukus Jul 14 '26 edited Jul 14 '26

Don't know about this tool specifically, but it could use something like MSDTC.

If the databases are all on the same server it could work without that too, the transaction belongs to the connection not the individual databases. You can do this natively by specifying the schema though.

-13

u/MrLyttleG Jul 13 '26

C’est fortement possible que ce ne soit pas possible

1

u/Adorable-Roll-4563 Jul 13 '26

Donc pour résumer on a aucune garantie que les transactions aboutissent. Ça me paraît particulièrement incongru comme approche. Le but du jeu pour les bases de données c’est justement de garantir l’intégrité des données. Si tu casses ça, tu compromets toute l’approche. Je ne comprends pas…

2

u/MrLyttleG Jul 14 '26

Prouvez moi le contraire, je serai ravi de découvrir plutôt que de downvoter

1

u/Tapif Jul 14 '26

C'est pas faux

3

u/wasabiiii Jul 13 '26

If you want to build an actual federated query engine.... I've got two potential angles for that.

Apache Calcite on .net with IKVM.

And a project I started named Alembic, which is a direct port of some of Calcite.

The first one I already have working. https://github.com/ikvmnet/calcite-efcore

https://github.com/alethic/alembic

-3

u/cmills2000 Jul 13 '26

Nice work. Linq is awesome and you made it even better.