Tutorial :Use subsonic 3.0 SimpleRepository to a existing database


I want to use subsonic 3.0 SimpleRepository in my project, but there is a problem :

If my table's name like Product etc. then I can't get any data from database, because subsonic generate the sql statement like "Select * from Products ..."

PS: I don't want to change my table name.

I wrote a t4 template to solve this problem, I hope someone can take a look at my code and tell me am i do the right thing?

Code: SimpleRepositoryDemo


It sounds like you already have a database designed in which case I would suggest you use the LinqTemplates or ActiveRecord instead. SimpleRepository seems to really be suited to a code first development process rather than a database first.


So it sounds like you have an existing database schema and an existing entity model (also known as a repository) and you want an ORM to push/pull data to/from your database and your application.

Unfotunately SubSonic is not the right tool for this scenario. SubSonic will create your entity model from your database schema or it will create your database schema from your entity model. But it won't map from one to another because it was designed with the idea of "convention over configuration". SubSonic is simple and that is its strength, but simplicity comes at a price.

What you need for this scenario is NHibernate. It was designed with lots of configurability. see http://nhforge.org/Default.aspx

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »