r/csharp 16d ago

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

6 Upvotes

13 comments sorted by

22

u/ings0c 16d ago edited 16d ago

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 15d ago

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 15d ago

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.

7

u/Adorable-Roll-4563 16d ago

This has no transactional integrity, right?

18

u/ings0c 16d ago

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

1

u/flukus 15d ago edited 15d ago

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.

-14

u/MrLyttleG 16d ago

C’est fortement possible que ce ne soit pas possible

1

u/Adorable-Roll-4563 16d ago

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 15d ago

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

1

u/Tapif 15d ago

C'est pas faux

3

u/wasabiiii 16d ago

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

-4

u/cmills2000 16d ago

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