|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Configuration;
using System.Data.Linq.Mapping;
using System.Reflection;
namespace MessageBoard.DataAccess.Linq
{
/// <summary>
/// Data context for the message board
/// </summary>
public class MessageBoardDataContext : DataContext
{
/// <summary>
/// Create a data context that uses the connection string
/// specified in the configuration file
/// </summary>
public MessageBoardDataContext()
: this(_connectionString)
{
}
/// <summary>
/// Create a data context for a specific connection string
/// </summary>
public MessageBoardDataContext(string connectionString)
: base(connectionString, _mappingSource)
{
}
// Default connection string read from the config file
static string _connectionString
= ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
//Initialize the ammping source read from the
//XML file in teh resource
static XmlMappingSource _mappingSource
= GetMappingSource();
private static XmlMappingSource GetMappingSource()
{
return XmlMappingSource.FromStream(
typeof(MessageBoardDataContext)
.Assembly
.GetManifestResourceStream("MessageBoard.DataAccess.Linq.Mapping.xml"));
}
/// <summary>
/// Member that maps to the Messages table in the database
/// </summary>
public Table<Message> Messages
{
get
{
return GetTable<Message>();
}
}
}
}
|
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.