Skip to content

Data.Linq.DataModel

Igor Tkachev edited this page May 20, 2016 · 1 revision

Home / Data / Linq

Data model creation

To build Linq queries we need a data model as a set of classes describing the structure of the database tables and relations between the tables. Building such a model can be done in the following ways:

  • Using T4 Templates.
  • Using the special utility for generating classes for BLToolkit from Andrew Smirnov.
  • Using Linq to SQL data model designer.
  • Writing data model classes manually.

Let’s see how a data model class representing Category table from Microsoft’s Northwind database should look:

[TableName("Categories")]
public class Category
{
    [PrimaryKey, Identity] public int    CategoryID;
                           public string CategoryName;
    [Nullable]             public string Description;
    [Nullable]             public Binary Picture;

    [Association(ThisKey="CategoryID", OtherKey="CategoryID")]
    public List<Product> Products;
}
Clone this wiki locally