Help with a design

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Jonoh89
Posts: 1
Joined: Fri 09 Dec 2011 16:32

Help with a design

Post by Jonoh89 » Fri 09 Dec 2011 17:19

I am looking at how to do the following and why the entity framework doesn't let me do what I want. I Am trying to use the designer first and build my database from it using the generate database :

I want:
1) a People table, which contains name etc
2) a customer table, which contains all the data from people + customer id and other related customer properties
3) a order table linked to the customerId with order details

I have created a person entity, created a customer entity which inherits from person and created a 1 to many association between customer and an order entity.
|Person|<----|Customer|1---------*|Order|

My problem is I can't create a primary key in the customer entity to relate with orders. Am i going about this the wrong way?

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Mon 12 Dec 2011 14:10

Jonoh89 wrote:My problem is I can't create a primary key in the customer entity to relate with orders. Am i going about this the wrong way?
Please try the following:
1. Create class Person with properties: ID (entity key), Name.
2. Create class Customer, then modify it:
a) add inheritance -
Base class: Person
Derived Class: Customer
Type: Table Per Type
b) add property Payment (any additional property).
3. Create class Order with properties: ID (entity key), Name. Then modify it:
a) add association
End 1 -
Class: Customer
Multiplicity: 1 (One)
Generate related property (selected)
End 2 -
Class: Order
Multiplicity: *(Many)
Generate related property (selected)
Add foreign key properties to the child class
and press OK.
b) rename just added property to CustomerID.
4. Right click on the diagram surface > Generate Database Script From Model, navigate through the wizard steps and make sure that the correct script for the database is generated.

Post Reply