tags:

views:

852

answers:

5

I have a bunch of POCO's that I created that I want to create a persistent layer for. Thing is, I really don't care how the data is stored in SQL Server, I just want it to be stored. In other words, I want to tell the ORM tool, "Here's some POCO classes, save them." and not have to do anything beyond that. Is there any ORM tool for C# that can do this? I've been struggling to get Fluent NHibernate working and Subsonic doesn't support relationships, which makes doing stuff like "Get all comments for a single post" pretty difficult. It needs to be able to automatically generate a database schema without me having to set a bunch of attributes and whatnot.

A: 

If you do not care how it is stored than why SQL Server? How about couchDB http://couchdb.apache.org/docs/intro.html

mfeingold
Because SQL Server is what our company and the client uses.
Daniel T.
+2  A: 

I personally use Fluent NHibernate and it does for me what you need. Well, almost. There're thing like need to manually specify ManyToMany but you can't avoid it. And if you want good entities design you have to make some members private, which disables automapping for these members. Still, I changed my design a LOT and never even thought about how my DB is changed (a luxury of a fresh project, but...).

Did you look at Castle ActiveRecord? Do you really need real POCOs, or you can live with attributes and .Save on entities? Well, I'd avoid that but it may work for you.

queen3
Two problems I ran into with Fluent NHibernate using automapping were that 1. it craps out when I tried to use a Dictionary column, and 2. it doesn't map enums, which I have a ton of. The first problem is understandable (I should've wrapped the key/value pair in a class instead), but I couldn't find a solution for the 2nd one.
Daniel T.
I use enums without problems. I had issues with that but google helped with simple solutions. There're many questions about this here, and it was easy to solve. Can't tell exactly now, but I just added IPropertyConvention as far as I remember, which tells to use GenericEnumMapper for enums, see http://stackoverflow.com/questions/439003/how-do-you-map-an-enum-as-an-int-value-with-fluent-nhibernate, though you may want to use CustomTypeIs(typeof(int)). Anyway, that is not the biggest problem with FNH ;-)
queen3
Turns out that Fluent NHibernate 1.0 RTM can automap enums just fine (to strings though), but can't do collections of enums. Looking into whether this is possible or not right now.
Daniel T.
Look here: http://www.mail-archive.com/[email protected]/msg04755.html. You probably need .AsElement().
queen3
+1  A: 

Check out Subsonics SimpleRepository. Create a class, make a database, give Subsonic a connection string and it handles the rest. Nifty.

CmdrTallen
SimpleRepository doesn't support relationships generation. It's fine if you have single objects that don't need relationships (like a single blog post), but what do you do in situations where you need a relationship (like comments that belong to a particular post)?
Daniel T.
A: 

Have a look at DevExpress's eXpress Persistent Objects

Khadaji
I took a look at it, but because you have to inherit from XPObject, it turns the POCO objects into persistence-aware objects.
Daniel T.
+6  A: 

You can try DataObjects.Net, but it is not exactly what you are looking for. First of all its entities are not poco, you must inherit them from certain base type. Second, you should mark fields you want to be saved with special attribute.

So why I recommend DataObjects then? Because I think it's fully black-boxes database. You just make a bunch of objects and ask ORM to save them.

  • It automatically generates database schema in specified RDBMS in runtime.
  • You don't have to call methods like .Save() to save changes, just work like with usual objects.
  • You don't have to write SQL queries - it fully supports LINQ.
  • You don't have to deal with SQL scripts even when existing database is being upgraded to next version.
Alex Kofman