Click here to Skip to main content
15,885,757 members
Articles / Web Development / ASP.NET

Enterprise Application Architecture with LINQ to SQL

Rate me:
Please Sign up or sign in to vote.
4.73/5 (44 votes)
17 Oct 200722 min read 294K   4.1K   277  
A discussion about architectural patterns for using LINQ to SQL in enterprise applications, along with performance implications
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Data;
using System.Data.Linq;
using System.Data.SqlClient;
using Northwind.Data;
using Northwind.Data.DTO;

namespace DLinqContext.Factory
{
    /// <summary>
    /// Uses the mapping file generated by SqlMetal.exe but loads it just once in 
    /// the app domain's life cycle.
    /// </summary>
    public static class SessionSingletonMappingSrc
    {
        static readonly MappingSource _mappingSrc;

        static SessionSingletonMappingSrc()
        {
            _mappingSrc = CreateMappingSource();
        }

        public static DataContext CreateDataContext()
        {
            return new NorthwindContext(CreateConnection(), _mappingSrc);
        }

        static IDbConnection CreateConnection()
        {
            return new SqlConnection(@"server=.; initial catalog=northwind; integrated security=SSPI");
        }

        static MappingSource CreateMappingSource()
        {
            return XmlMappingSource.FromReader(new XmlTextReader("northwindMapping.xml"));
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I am a tech lead working for Cap Gemini. Although I primarily work with the Microsoft technology stack (including .NET and legacy technologies) I like to keep myself informed about developments in the Java world.

Comments and Discussions