SubSonic 3 Frequently Asked Questions

Contents

Summary

Answers to some of the more common questions asked about SubSonic asked on stackoverflow.

General SubSonic questions

How do I extend the generated SubSonic classes?

All the generated SubSonic classes are partials so all you need to do to add extra properties/methods to them is to create your own partial class with the same name in the same namespace and the two will be merged at compile time. For example you extend the a generated Customer class as follows:

public partial class Customer
{
  public string FullName
  {
    get 
    {
       return // Format and return the customer's full name here
    } 
  }
}

http://stackoverflow.com/questions/1480286/adding-properties-to-an-existing-object-retreived-using-subsonic/1481772#1481772

How do I know if a database operation has succeeded?

Unless a DbException is thrown then the operation has succeeded.

http://stackoverflow.com/questions/1141195/subsonic-3-0-general-questions

How do I fix the error "Metadata file 'System.Data.SQLite' could not be found"?

Make sure you have SQLite installed on your machine and the SQLite .NET driver referenced in your project.

http://stackoverflow.com/questions/1319103/active-record-and-linq-t4-templates-problem

How do I add DataAnnotations to my generated class?

You need to create a buddy class and apply the Data Annotations to that class:

[MetadataType(typeof(ContactValidation))]
public partial class Contact
{
}
 
public class ContactValidation
{
  [DataType(DataType.EmailAddress, ErrorMessage = "Please enter a valid email address")]
  public string Email { get; set; }
}

http://stackoverflow.com/questions/1232497/adding-dataannontations-to-generated-partial-classes

How do I use a transaction?

http://stackoverflow.com/questions/910863/using-transactions-with-subsonic

My Table/Column names are causing problems. How can I get round this?

The CleanUp() function was built for this - it's in Settings.tt. You should be able to rename your class as needed.

http://stackoverflow.com/questions/1409925/table-and-column-names-causing-problems

How can I retrieve just the value of one column from a table?

To do this using Linq:

var query = from customer in Customer.All()
  select new {
    customer.CustomerAddress
  }

http://stackoverflow.com/questions/1402512/what-is-easiest-way-to-retreive-one-columns-values-using-subsonic-column-isnt

Why aren't the t4 templates working?

If the templates don't run automatagically you should just be able to right click on them and choose 'Run custom tool'. If that doesn't work it's probably because of one of the following: