开发者

How to talk to a database in a portable way?

开发者 https://www.devze.com 2022-12-08 10:23 出处:网络
I\'d like to start an application that makes heavy use of a database, and is supposed to run on Windows under .NET as well as Mac/Linux under Mono.

I'd like to start an application that makes heavy use of a database, and is supposed to run on Windows under .NET as well as Mac/Linux under Mono.

Having done some research, I've re开发者_Python百科alised that neither LINQ-to-SQL nor LINQ-to-Entities are production-ready in Mono at the moment (here and here). According to the former link, LINQ-to-SQL may at least make it into Mono 2.6, due some time in Nov 2009.

Mono also implements ADO.NET 2.0, as far as I can tell, although the test results are not looking great (assuming the page is up-to-date). Also, using raw ADO.NET is going to be very painful compared to LINQ.

Which database access API would you guys recommend in this situation?


If you want an ORM, use NHibernate. If you don't need an ORM, use ADO.NET.


I'd recommend coding by interface here. One of the great things about .NET is that it makes heavy use of interfaces, so you could code against IDbConnection, IDbCommand and so on. This means that you can code your application in ADO.NET to be virtually database/provider agnostic.


Here is a link with the ADO.Net Data providers that Mono supports:

http://www.mono-project.com/Database_Access

You do not say which database you will be using when running on Mono. Linq to SQL is only supported for MS SQL Server.

As others have said, it looks like nHibernate is the way to go.


After much research I have discovered SubSonic, which looks to be much closer to the LINQ-to-SQL model than nHibernate. Just mentioning it since nobody else has. Not sure yet if this will be the final choice.


For the record, we settled on IQToolkit together with a custom tool to generate classes from a database. The result is more low-level than ActiveRecord-style approaches; essentially nothing more than adding strong typing and LINQ support on top of SQL.

0

精彩评论

暂无评论...
验证码 换一张
取 消