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

Using Default Join Table

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.

This topic demonstrates how to create many-to-many associations by using the (Default) option for a join table.

Suppose, you have the following domain model:

Both entities are mapped to tables. For this scenario, it doesn't matter whether the domain classes are default or explicitly mapped. To create a many-to-many association between the Customer and Order entities:

  1. Create a new association between your entities.
  2. In the Association Editor, navigate to the Relational View.
  3. Check the Use Join Table option.
  4. From the drop-down, select (Default).

  5. Click OK to submit the changes and close the editor.

Using the (Default) option for a join table means that when you migrate your database schema to the latest model state, Telerik Data Access will create a join table that will handle the many-to-many relation. For example, see the customer_order table in the script below. It will be used as a join table.

-- OpenAccessModel.Customer
CREATE TABLE [customer] (
   [nme] varchar(255) NULL,                -- _name
   [id] INT NOT NULL,                      -- _id
   CONSTRAINT [pk_customer] PRIMARY KEY ([id])
)
GO

-- System.Collections.Generic.IList`1 OpenAccessModel.Customer._order
CREATE TABLE [customer_ordr] (
   [id] INT NOT NULL,
   [id2] INT NOT NULL,
   CONSTRAINT [pk_customer_ordr] PRIMARY KEY ([id], [id2])
)
GO

-- OpenAccessModel.Order
CREATE TABLE [ordr] (
   [order_date] datetime NOT NULL,         -- _orderDate
   [id] INT NOT NULL,                      -- _id
   CONSTRAINT [pk_ordr] PRIMARY KEY ([id])
)

GO
CREATE INDEX [idx_cstmr_ordr_id2] ON [customer_ordr]([id2])
GO

ALTER TABLE [customer_ordr] ADD CONSTRAINT [ref_cstmr_rdr_cstm] 
FOREIGN KEY ([id]) REFERENCES [customer]([id])
GO

ALTER TABLE [customer_ordr] ADD CONSTRAINT [ref_cstmr_rdr_ordr] 
FOREIGN KEY ([id2]) REFERENCES [ordr]([id])
GO