开发者

Linq2sql on different SQL Server Schemas

开发者 https://www.devze.com 2023-01-19 11:19 出处:网络
I have a application which is running in both production and development environments. I would like to utilize the databases better (and save money on my hosting bill) so i want to be able to make my

I have a application which is running in both production and development environments. I would like to utilize the databases better (and save money on my hosting bill) so i want to be able to make my Linq2Sql run on two different schemas (instead of two different databases) (there are ~15 tables in a schema). H开发者_如何学Goow to set this up in Linq2Sql?

Or should i go the distance and read up on Entity Framework instead (and is it possible to segment the tables based on schemas in this one?

Any other solutions to this problem are welcome?


This is actually easier to do in LINQ to SQL than it is in EF. Not that it is terribly easy, mind you. I wrote a blog post a couple of years ago on how to do it but the heart of it is to specify the mapping source in your context constructor.

XmlMappingSource source = XmlMappingSource.FromUrl("TestLINQ.map");
// Could also use XmlMappingSource.FromXml(string)
using (LINQ.TestLINQDataContext context = new LINQ.TestLINQDataContext(Properties.Settings.Default.TestConnectionString, source))
{

Using this method, you can alter your mapping source to point at the schema (or table name) that you want to.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号