Untie the Connection String from DataContext (LINQ to SQL)

When you work with LINQ to SQL you probably want your DataContext (and all the entities) to be in its own assembly. It’s a normal decision when developing n-tier applications.

The Problem

When you create your LINQ to SQL classes file (dbml) you have two options for your database connection string:

  1. In Settings.settngs file of the corresponding assembly
  2. Hard-coded in your DataContext desginer (.designer.cs file)

Well, when you have a web application or WinForms/WPF application you definitely would like to manage your connection string from the general config file (web.config or app.config). In this situation it would be a little pain. Continue Reading…

Mapping a Stored Procedure to an Entity with Entity Framework

ADO.NET Entity Framework initially generates a 1:1 (one to one) mapping between the database schema and the conceptual schema in most of the cases. In the relational schema, the elements are composed of the tables, with the primary and foreign keys gluing the related tables together. In contrast, the Entity Types define the conceptual schema of the data. One is sure – ADO.NET Entity Framework makes it easy when it comes to work with a database. But is it sure?

Suppose you have created your entities using the Visual Studio 2008 wizard.
ADO.NET Entity Framework

Continue Reading…