Database Reference
In-Depth Information
constraint PK_Customers
primary key clustered(CustomerId)
);
create table dbo.Orders
(
OrderId int not null identity(1,1),
CustomerId int not null,
OrderNo varchar(32) not null,
constraint PK_Orders
primary key clustered(OrderId),
constraint FK_Orders_Customers
foreign key(CustomerId)
references dbo.Customers(CustomerId)
);
create index IDX_Orders_Customers on dbo.Orders(CustomerId);
create table dbo.OrderItems
(
OrderId int not null,
OrderItemId int not null identity(1,1),
Qty float not null,
Price money not null,
constraint PK_OrderItems
primary key clustered(OrderId, OrderItemID),
constraint FK_OrderItems_Orders
foreign key(OrderId)
references dbo.Orders(OrderId)
);
Listing 16-4 shows the Entity Framework model that corresponds to the database schema.
Listing 16-4. Entity Framework model
public class Customer
{
public Customer()
{
Orders = new HashSet<Order>();
}
public int CustomerId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public int? CreditLimit { get; set; }
public byte[] Photo { get; set; }
public byte[] Ver { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
 
Search WWH ::




Custom Search