views:

550

answers:

2

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 write 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?

Thx

Code: SimpleRepositoryDemo

+3  A: 

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.

Adam
Yes, it is a existing project.But if i use the LinqTemplates or ActiveRecord, i have to convert my entity to subsonic generated entity before insert a new record to the database
Nick Yao
Yes you will, but if you used the LinqTemplates I would expect that you could replace your existing entities with the generated ones, moving any required existing functionality into partial classes.
Adam
But i don't want to change my entity.1. I want to keep my entity simple2. Moving hundreds of entities is not a easy job
Nick Yao
+3  A: 

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

Mark Arnott
+1 for NHibernate
mxmissile