Welcome to WindowsClient.net | Sign in | Join

Zuker On Foundations

The realm of .NET (WPF, WCF and all around)

LINQ to SQL Dynamic Mapping

Via this post.

The post discusses the issue of using LINQ-to-SQL with dynamic mappings.

The problem
You have SQL Servers for each of your environments (development, test, pre-prod, production) and in each one, the table names are different.  In fact, it’s not the table names that are different but the schema names but since the schema name is part of the table name, it must be specified.
Ex : dev.ZeTable et prod.ZeTable

Easy to solve, right?  Just put the schema value in the config file and do a simple concatenation at runtime.  Well, it’s not as easy as it seams because the table name is stored in an attribute of the partial class generated by the LINQ to SQL designer and Microsoft didn’t provide a way or method to change it at runtime.

[Table(Name="dev.ZeTable")]
public partial class TheTable

Solution
The solution is to dynamically load at runtime a mapping specific for each environment.
Here’s how to do it:. (Go to the post..)

Posted: Aug 10 2008, 11:18 AM by zuker | with no comments
Filed under:

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Page view counter