Selecting Templates


Contents

Summary

With choice comes trouble - sometimes it's just easier to do what the tool tells you to do (hammer says "hit nail"). SubSonic's not really that way - our goal is to give you as many different ways as you need to work with your data - our goal is to help, not tell you what to do. So we lend a hand and get out of your way.

That said - here's a summary of what each approach does for you with SubSonic 3.0.

ActiveRecord

ActiveRecord is especially simple to work with, and abstracts the most for you. Your objects are generated from the tables in your database, with IQueryable foreign keys. You can work with Linq if you like, or you can save some time working directly with Factory methods for getting data.

ActiveRecord also mocks out your database automatically by setting your connection string to "Test". This will allow you to work against in-memory lists rather than hit the database.

You can read more about Using ActiveRecord here.

SimpleRepository

If code generation is not your thing and your database is there to (mostly) store your application's data - then SimpleRepository is for you. Many applications (like a Blog, for example) have a very light "need" when it comes to storing data - so why use a massive data access pattern?

SimpleRepository is very, very easy to use and it also creates your tables for you, on the fly, as needed. If you change your model, the repository will alter your database (not dropping any tables - simply altering them).

With SimpleRepository you're working with POCOs - not an object set that is built on a heavy base class. For many this is optimal.

Linq Templates

This template set was the original build for SubSonic's T4 Template approach, and approximates, to a high degree, Linq To SQL's approach to data access.

This set of templates is somewhere between SimpleRepository and ActiveRecord: you get to work with POCOs but you also have a nice degree of abstraction using some basic code generation.