-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
In the age of cloud it becomes more common to shard across databases based on tenant, geography and scaling needs. EF should support querying across databases better.
It's not enough to change the connection string because one query might need to pull from multiple databases. Example: Join customer-specific data with master data.
I think it's really required that EF allows us to specify the database name per table reference. A strawman:
from o in db.Orders.WithDatabase("NewYork-Tenant1234") join c in db.Customers.WithDatabase("NewYork-master") on ... select new { o, c }This is supposed to be a scenario where the database name depends on a geographical sharding as well as on the tenant name. Both are dynamic and can change for every query. Connection strings cannot do this. Statically configured database names cannot do that either.
This query would translate to:
select * from [NewYork-Tenant1234].dbo.Orders o join [NewYork-master].dbo.Customers c on ...The same configuration mechanism would lend itself well to configuring hints such as
NOLOCKor the commonUPDLOCK, ROWLOCK, HOLDLOCKcombination. This is unrelated to this issue but I'm mentioning this to justify with theWithDatabasesyntax makes sense.A simple extension to this would be to allow completely dynamic table names.
WithTableName(database, schema, name)would map todatabase.schema.nameon the SQL side. This is useful for example when sharding by date with one table per day. SQL Server Standard Edition does not have partitioning.What is the team's stance on supporting such scenarios?