Subsonic custom mapping of objects to tables
Asked Answered
C

1

13

I'm using Compact Framework 3.5 and have tentatively settled on a custom build of Subsonic 3.0 to do data access. The trouble is that I am used to developing model-first but am also interested in keeping control of my DB schema. Therefore, neither ActiveRecord or Repository appears to meet my needs, and I want to use my existing POCO model and map it to my existing tables. I'm used to doing this via NHibernate and Entity Framework.

After some investigation, it appears that I might be able to author a custom QueryMapping to give me the custom mapping I want. Before I start down this path, however, I'd like to see some kind of example of this being done. I can't seem to find any on the web, and wonder if anyone could give input on experience with Subsonic, model-first and a custom Table-per-Type and Table-per-Hierarchy mapping.

Crosslegged answered 13/12, 2009 at 6:2 Comment(0)
F
1

As of SubSonic 3.0.x:

If you want to use POCOs, you very much want the Repository -- the SimpleRepository in particular. SubSonic only supports a table-per-type model. SubSonic does not support inheritance. If you want it, you'll have to code it; however, that's not of reach if you're motivated to take it on.

The SimpleRepository does, however, offer a respectable amount of control over schema -- even when using (auto)migrations (which I find quite addictive for POCO-first). Be sure to checkout the good documentation on the project site, in particular http://www.subsonicproject.com/docs/Using_SimpleRepository. Pay attention to the attribute usage. New attributes are easy to create and integrate to a custom repository service class.

Perhaps the best thing about SubSonic's SimpleRepository: it's very easy to extend. Our team has extended it quite a bit (e.g. adding eager-loading support), and overall, we all find it very enjoyable to hack on. It has a very pleasant design, it's fast, lightweight, and doesn't draw attention to itself.

Best of all, SimpleRepository + Migrations encourage a sane schema design. If you find yourself fighting SubSonic, you need to check yourself; more likely than not, you're steering your boat into the weeds.

If you need more database versioning firepower, combine it with migrator.net for an easy win.

Good luck, and welcome to SubSonic!

Ferry answered 31/3, 2011 at 1:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.