tags:

views:

18

answers:

1

is there any option to prefix LINQ2SQL entities like modifying a T4 template or anyconfiguration change?

A: 

Actually there is. The solution is manual, you have to do it for each mapped entity. Just open the DMBL in the designer, then select any table, then go to properties. The "name" field is the code representation of your entity so you could name it "_customers". The source field is the DB table name so that could still be "customers" without an underscore or any other value you may have.

Since you mentioned T4, maybe you want something a little bit more automated. We regen the DBML using T4 on a few of our projects, mostly we do this to gain testability on the data context. In your T4 you would simply wrap a property with your desired prefix around the entities to return that entity.

You can view his blog post about the T4 bits here. http://melgrubb.spaces.live.com/blog/cns!A44BB98A805C8996!256.entry

The line to get the tables is... var Tables = (from t in root.Elements(NS + "Table") select new ContextType(NS, t)).ToList();

Hope that gets you most of the way there.

Chris Farrell

Chris Farrell