简体   繁体   中英

Best practice when querying restored databases

I am developing an application that is differentiating between an existing database and a backup-file ( .bak ). When generally connecting and retrieving data from SQL Server, I prefer to use Linq, since I find it easier to use this when building queries.

In this case I do not see how I can do this, my procedure is that I construct a string with the SQL query for restoring the database (from the .bak file) and then retrieve whatever data that differs from the current one, with this one.

All queries that I use are strings which I format to add the database-name and schema. The strings that I am using become quite large and I find that it is very cluttering (I like clean code).

The structure of the databases are all the same and do not ever change between the different backups or the real deal. New backups come each day, and have to be checked against, so it isn't really an option to go in and add a new connection-file each time there is a new backup.

Is there any way that I can restore the database, using Linq, and then retrieve the data using Linq queries? Or am I doing it as I should?

You can only use Linq for queries so you can not use it to restore a database.

Also, you can't use different databases in the same Linq query, you can however materialize the results of each query to the database and make a third Linq query based on them, as you can see in this answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM