Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework Mapping Question
    primarykey
    data
    text
    <p>Trying to map the following schema using the Entity Framework.</p> <ul> <li>A Customer can have many associated Stores. </li> <li>A Store can have many associated Customer </li> <li>Each Store can have 0 or 1 and only 1 TopCustomer (the criteria to be a TopCustomer is determined in the business logic) </li> </ul> <p><img src="https://imgur.com/ZbEGD.gif" alt="alt text"></p> <p>this results with the following mapping in VS. </p> <p><img src="https://imgur.com/CZyp5.gif" alt="alt text"></p> <hr> <p>Here's the DB Script :</p> <pre> <code> USE [TestDb] GO /****** Object: Table [dbo].[Customer] Script Date: 06/20/2009 09:53:52 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Customer]( [CustomerId] [uniqueidentifier] NOT NULL, [FirstName] [nvarchar](50) NOT NULL, [LastName] [nvarchar](50) NOT NULL, CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED ( [CustomerId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[Store] Script Date: 06/20/2009 09:53:52 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Store]( [StoreId] [uniqueidentifier] NOT NULL, [StoreName] [nvarchar](50) NOT NULL, [TopCustomer] [uniqueidentifier] NULL, CONSTRAINT [PK_Store] PRIMARY KEY CLUSTERED ( [StoreId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[CustomerStore] Script Date: 06/20/2009 09:53:52 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[CustomerStore]( [CustomerId] [uniqueidentifier] NOT NULL, [StoreId] [uniqueidentifier] NOT NULL, CONSTRAINT [PK_CustomerStore] PRIMARY KEY CLUSTERED ( [CustomerId] ASC, [StoreId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: ForeignKey [FK_CustomerStore_Customer] Script Date: 06/20/2009 09:53:52 ******/ ALTER TABLE [dbo].[CustomerStore] WITH CHECK ADD CONSTRAINT [FK_CustomerStore_Customer] FOREIGN KEY([CustomerId]) REFERENCES [dbo].[Customer] ([CustomerId]) ON UPDATE CASCADE ON DELETE CASCADE GO ALTER TABLE [dbo].[CustomerStore] CHECK CONSTRAINT [FK_CustomerStore_Customer] GO /****** Object: ForeignKey [FK_CustomerStore_Store] Script Date: 06/20/2009 09:53:52 ******/ ALTER TABLE [dbo].[CustomerStore] WITH CHECK ADD CONSTRAINT [FK_CustomerStore_Store] FOREIGN KEY([StoreId]) REFERENCES [dbo].[Store] ([StoreId]) ON UPDATE CASCADE ON DELETE CASCADE GO ALTER TABLE [dbo].[CustomerStore] CHECK CONSTRAINT [FK_CustomerStore_Store] GO /****** Object: ForeignKey [FK_Store_TopCustomer] Script Date: 06/20/2009 09:53:52 ******/ ALTER TABLE [dbo].[Store] WITH CHECK ADD CONSTRAINT [FK_Store_TopCustomer] FOREIGN KEY([TopCustomer]) REFERENCES [dbo].[Customer] ([CustomerId]) GO ALTER TABLE [dbo].[Store] CHECK CONSTRAINT [FK_Store_TopCustomer] GO </code> </pre> <hr> <p><strong>Question :</strong></p> <p>How can the TopCustomer association be mapped to a single instance of Customer without creating an extra navigation property on the Customer class ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload