Reputation: 15
I have heard that Linq query write once can be run on SQL and MS Access database too. Is it right or wrong?
For example I want to write queries once regardless of database type like currently I'm using MS Access database and later then if I wish to move on to SQL Server then I don't want to change my queries. Is this possible??
Upvotes: 1
Views: 191
Reputation: 597
Basically, you can use Linq to Objects and work with any dataset.
If you want to save your logic and specific - I recommend you to use Devart LinqConnect.
Also, you can read more about simultaneous Oracle and MS SQL usage in given article. Approaches will be the same for LinqConnect.
Upvotes: 0
Reputation: 9469
If you use Entity Framework, you can find/buy several provider for different data sources.
As soon as you have enough abstraction over the entity context, you can use any LINQ construct to build your queries. But keep in mind that not all providers support the same operators and functions. You will still have to test the complete application during a DBMS change.
Upvotes: 0
Reputation: 30646
LINQ-to-SQL will only work with SQL server. Linq to objects will work on most any collection, but you lose the deferred execution.
Upvotes: 0
Reputation: 1063774
It depends in part on the queries. For simple queries (select, where, orderby) you should be fine, but there are a lot of implementation-specific details.
For example:
First
on a set you haven't explicity ordered : LINQ-to-SQL is fine with that, LINQ-to-Entities will failExpression.Invoke
to build a gnarly custom expression : again, LINQ-to-SQL is fine, LINQ-to-Entities will fail.Where(predicate).FirstOrDefault()
vs .FirstOrDefault(predicate)
- which are semantically identical, but IIRC only one works (in Astoria)My point is; it might work, but you do need to test against the specific implementation.
Upvotes: 2