Data Access has been discontinued. Please refer to this page for more information.

How to: Set the Identity of the Classes

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

Each domain class has a primary key (identity) that is based on one or more scalar properties of the class. As in relational database, these key values are used to verify the uniqueness of a given entity and to improve the performance of queries. Usually, primary key properties are mapped to a key column in the underlying table, either an identity column or some other column that is constrained to guarantee a unique value.

This topic demonstrates how to set identity of domain classes:

Setting a Single Primary Key

To set a single primary key:

  1. Select the target domain class and then select the property you want to be a primary key. In case of this demo this is the Customer.Id property.
  2. Press F4 to open the Properties Pane.
  3. Set the Identity property to True.

When you create/migrate your database by using the Update Database from Model Wizard, the Id column will be the primary key for the Customer table. The generated the generated DDL script will be:

CREATE TABLE [Customer] (
   [typ] INT NOT NULL,                     -- _type
   [nme] varchar(255) NULL,                -- _name
   [Id] INT NOT NULL,                      -- _id
   CONSTRAINT [pk_Customer] PRIMARY KEY ([Id])
)
GO

Setting a Composite Primary Key

To set a composite primary key:

  1. Select the target domain class and then select the properties you want to be part of the composite primary key.
  2. Press F4 to open the Properties Pane.
  3. Set the Identity property to True.

When you create/migrate your database by using the Update Database from Model Wizard, the OrderId and OrderDetailId columns will be primary keys for the SalesOrderDetail table. The generated the generated DDL script will be:

CREATE TABLE [SalesOrderDetail] (
   [UnitPrice] NUMERIC(20,10) NOT NULL,    -- _unitPrice
   [OrderId] INT NOT NULL,                 -- _orderId
   [OrderDetailId] INT NOT NULL,           -- _orderDetailId
   [Discount] NUMERIC(20,10) NOT NULL,     -- _discount
   CONSTRAINT [pk_SalesOrderDetail] PRIMARY KEY ([OrderDetailId], [OrderId])
)
GO