1

Basically I'd like to do what LINQ does and load & save my objects without queries. Any tips?

It looks like I'm trying to emulate LINQ to SQL an Object Relational Mapping.

stormist
  • 5,709
  • 12
  • 46
  • 65
  • 3
    an object relational mapping? – Mare Infinitus Jul 21 '12 at 19:34
  • 1
    LINQ doesn't do that. It just allows you to query _in memory_ collections. It doesn't handle the loading and saving (unless you are talking about LINQ to SQL, which is an ORM). – Oded Jul 21 '12 at 19:37

1 Answers1

4

What you are asking for looks like an Object-relational mapper with LINQ provider.

For instance, NHibernate ORM (my personal favorite) supports both PostgreSQL and MySQL. As of version 3.0 it has a built in LINQ provider.

Microsoft's Entity Framework doesn't have out of the box support for many database engines, as NHibernate has, but there are third party solutions. Btw, EF got open-sourced two days ago.

There's an interesting site that compares various ORMs in .NET world - ORM Battle. There you can find a list of other popular ORMs and see how they compare to each other.

Some SO ORM questions:
https://stackoverflow.com/questions/132676/which-orm-for-net-would-you-recommend
Best ORM to use with C# 4.0

Also, micro-ORMs have recently risen in popularity. They don't really offer a full object to database mapping, nor Linq support (most of them) but they could be a good tool for the job.

Community
  • 1
  • 1
Miroslav Popovic
  • 12,100
  • 2
  • 35
  • 47
  • 2
    Though there are _many_ other ORMs. Entity Framework, Dapper and more. – Oded Jul 21 '12 at 19:45
  • Thank you! This is awesome- Can you clarify something I'm confused about: Does the computer I install my program on have you also have the database installed or can I bundle that with my program? – stormist Jul 21 '12 at 19:47
  • It really depends on the database used. For instance, if you are using SQL Server compact edition, you only need few dlls for engine and a database file - all of which can be XCopy deployed. For full SQL Server, you need to have the database system installed, but of course, you could bundle it within a custom installer. Not sure what are requirements for PostgreSQL and MySQL. – Miroslav Popovic Jul 21 '12 at 19:51
  • @Oded yep, +1... didn't mentioned others, since I'm not familiar with their support for OP requirements (PostgreSQL, MySQL and LINQ). For instance, Entity Framework supports only SQL Server family out of the box (and maybe Oracle). – Miroslav Popovic Jul 21 '12 at 19:54
  • @Oded I have updated my answer with more links to other ORMs. Thanks. – Miroslav Popovic Jul 21 '12 at 20:08
  • 1
    @MiroslavPopovic PostgreSQL isn't wonderful for in-app embedding as it requires a separate server process. It's not bad though. You can bundle the binaries in your installer, `initdb` a database, and start/stop the server from your program. I'd avoid using the EnterpriseDB installer for in-app bundling as you can cause conflicts with a copy of PostgreSQL installed manully by the end user. – Craig Ringer Jul 22 '12 at 03:04