how to write database independent layer using Linq - linq

How I can write database independent, data layer using Linq to Sql? For example I have one dbml file, which I can use with almost any database at runtime ( by specifying web.config)
Entity framwork is a better option, but it is not implemented in Mono so I can't use it.
Edit: I mean different databases like Sql Server, Mysql or SqlLite. I prefer to use DbLinq for other databases.
Edit 2 :
I have created Linq to Sql mapping class by following this blog post.
http://blogs.msdn.com/b/spike/archive/2010/01/08/how-to-use-linq-to-sql-without-using-the-designer-generated-classes.aspx
Now how I can use this with other databases.

You need a 3rd party linq provider like ALinq http://www.alinq.org/ that suports Mono.
As it is structured from Microsoft, Linq to SQL is VERY database dependent, ie it only works with MS SQL. I believe that ALinq does work on mono. Here's a better list of 3rd party providers:
http://blog.linqexchange.com/index.php/links-to-linq-providers/

Related

Couldn't find the Oracle Data source in visual studio 2012 while adding the ado.net Entity Model

This is my first time with MVC. When I am trying to add an ADO.net entity model then while creating a new connection I couldn't see my oracle database in the list of data source name. Only different type of Microsoft server is listed. What should I do to get the oracle database listed there too. When using simple database connection in the desktop application I could see the oracle database listed but not in this case.
The main problem is I couldn't connect entity data model to oracle database
I think you need to install the Oracle Developer Tools, which is a surprisingly complicated process.
This is a rather old article, but I think this is still useful
http://blogs.msdn.com/b/kaevans/archive/2009/07/18/connecting-to-oracle-from-visual-studio.aspx

Independence though ODBC drivers

Can an application developed with oracle queries in DB layer
Be run on an SQLServer Database with the help of an ODBC driver
Maybe, if you used only ANSI SQL statements. ODBC will happily send the text of the query to the query parser on the server and as long as the server can parse it, it will run.
If, however, you have used anything that's specific to Oracle (and that's a long, long list), then it won't work so well.
All that ODBC provides you is abstraction from the connection details -- the driver, the server name, the port numbers etc.
So, how do you get true independence? Generally, you'll use a query generation library like Hibernate which knows how to translate a query language of some kind (HQL) to the specifics for that particular database (PL/SQL or Transact/SQL).
Short answer: Not reliably.
Longer answer: Not through ODBC, but using a JDBC driver for Microsoft SQL Server then perhaps if the application was developed only with ANSI standard SQL. Usually, that is not the case and some PL/SQL code will have been used. If an equivalent piece of T-SQL can be written then it is possible to port the application. But, to your question, this is largely immaterial to the database connection mechanism.
Addendum: Object Relational Mapping tools usually use dialects to generate database independent queries. Other options include using configuration to select the correct queries at run-time (if you need to support both database types).

Oracle with IQueryable

I was having a bit of trouble figuring this out so I thought I'd ask explicity...
Does oracle's ODP.Net or ODT entity framework support IQueyable - ie. If I create simple paging or query in linq will it run the query on the database?
I'm roughly aware that there are commercial products that will work with oracle to do this - I see DevArt pop up quite a bit.
Thanks,
Sam
You can use NHibernate to run LINQ queries against Oracle database.
NHibernate uses it's "language" called HQL to talk to various databases. And they also built LINQ provider that creates HQL that is in the second phase sent to target DB.
After a bit more searching, it appears the ODP.Net will convert queries into SQL code, but ... poorly on occasion?
see
https://community.oracle.com/thread/2598619
for details & more relevant resources see
https://community.oracle.com/community/developer/english/oracle_database/windows_and_.net/odp.net/content
& enter tag "paging"
According to the last comment in the thread https://community.oracle.com/thread/2349719, linq actully generates the SQL.. interesting

Entity framework join to ms-access

I want to ask you is any way to generate or updating access database from entity framework, I have a serious problem I have a database using ms-access and it is expensive for me if I want to change to sql server ?
I need to use entity framework functionality. could you give me a solution ?
If you want to use MSAccess don't use EF. If you want use EF, don't use MSAccess.
Entity Framework does not support Access. But you can migrate to SQL Express (at no cost) and use EF for your applications.
SQL Express is free and enought for small databases.
Alternatively, if you want a desktop database, you can use SQLite. NET driver for sqlite supports EF.

open one sql express db in multiple projects

I would like access a sql express db in multiple projects, a dynamic data project to administrate the data and a console application which fetches the data from the db, is there an option to do this? or should I use a SQL CE for this kind of scenario?
A database is meant to be accessed from different clients. You can specify the same connection string in both projects, Dynamic Data and Console. SQL Server Express will handle traffic from both over the network easily.
You can use different data access strategies as well, in both projects. LINQ To SQL, DIY ADO, SubSonic, etc.

Resources