Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subsonic custom mapping of objects to tables

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.

like image 499
codekaizen Avatar asked Dec 13 '09 06:12

codekaizen


1 Answers

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!

like image 69
Zack Avatar answered Sep 18 '22 15:09

Zack