I have a ASP.NET MVC 4 application with EF and I’m not using CodeFirst.
I want my SQL tables to look like this :
Orders 1 —- 0…1 OrdersWithShipment
CREATE TABLE Orders (
OrderId int NOT NULL IDENTITY(1,1),
OrderDate date NOT NULL,
OrderNo int NOT NULL,
ShipmentId Int NULL
CONSTRAINT [Orders_PK] PRIMARY KEY CLUSTERED
(
[OrderId] ASC
))
CREATE TABLE OrdersWithShipment (
ShipmentId int NOT NULL IDENTITY(1,1),
OrderId int NULL,
ShipmentDate date NOT NULL
CONSTRAINT [OrdersWithShipment_PK] PRIMARY KEY CLUSTERED
(
[ShipmentId] ASC
))
Q : What do I need to do (in SQL and EF) so that I have a 1 — 0…1 relationship ?
Edit :
Can I use unique filtered index link
This is how an
1..0-1could be defined in SQL (ShipmentIdremoved from both tables):