I have 10 identical databases.
I get the database names at runtime.
I want to store rows into a collection of objects.
I also only want one hit on the database server.
My current approach:-
- In a query (no stored procedures for X reason) I get list of databases and store in a temporary table.
Then I iterate through each database and create a dynamic query and execute it.
DECLARE @MaxRownum int SET @MaxRownum = (SELECT MAX(RowNum) FROM #Databases) DECLARE @Iter int SET @Iter = 1 WHILE @Iter <= @MaxRownum BEGIN DECLARE @Database varchar(255) SELECT @Database = Databases FROM #Databases WHERE RowNum = @Iter IF HAS_DBACCESS(@Database) > 0 BEGIN //appending query END SET @Iter = @Iter + 1 END EXEC(@Query)
Can I use Linq + entity framework with one hit to server, without dynamic query and without hampering the performance? Is there any better solution?