3

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.

Daniel T.
  • 37,212
  • 36
  • 139
  • 206
  • Subsonic does support relationships if there are foreign key relationships in the database. It should be as simple as iterating `Post.Comments`... – John Rasch Oct 01 '09 at 21:37
  • Yes, if you are using ActiveRecord and going bottom-up. However, I'm doing top-down using SimpleRepository, and so far it doesn't support relationships yet. – Daniel T. Oct 01 '09 at 21:51
  • Issues tend to come up when the Reporting group wants to query against the auto-generated schema six months from now. Personally I'd design my classes, design my tables and relations (possibly with assistance from DBAs), then map them. – TrueWill Oct 02 '09 at 01:36
  • In my case, there's no DBA, reporting group, quality assurance, or anything else. It's just me, the IDE, and a looming deadline :). – Daniel T. Oct 02 '09 at 19:33

5 Answers5

6

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
  • 2,153
  • 19
  • 20
2

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
  • 15,333
  • 8
  • 64
  • 119
  • 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. Oct 01 '09 at 21:55
  • 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 Oct 01 '09 at 22:09
  • 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. Oct 02 '09 at 03:45
  • Look here: http://www.mail-archive.com/fluent-nhibernate@googlegroups.com/msg04755.html. You probably need .AsElement(). – queen3 Oct 02 '09 at 07:22
1

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

CmdrTallen
  • 2,264
  • 4
  • 28
  • 50
  • 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. Oct 01 '09 at 21:58
0

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

mfeingold
  • 7,094
  • 4
  • 37
  • 43
0

Have a look at DevExpress's eXpress Persistent Objects

Khadaji
  • 2,147
  • 2
  • 17
  • 19
  • 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. Oct 01 '09 at 23:26