user1005310
user1005310

Reputation: 877

Table Splitting in SQL and represent in code first C#

I have 2 tablesin SQL , rather it should have been 1 table but I split into 2 tables and represented in POCO as below

Public class Order                    
{
    [Key] 
    public string OrderID {get;set;}
    public string OrderName {get;set;}
}

Public class OrderDetail                    
{
    [Key] 
    public string OrderDetailID {get;set;}
    public string OrderQRCode {get;set;}

    [ForeignKey] 
    public string OrderID {get;set;}
}

its one to one relation, How do I represent this in code first approach ? Getting "Multiplicity is not valid in Role" issue ? Life would have been easier with one table and 2 column names OrderName,OrderQRCode but cause of business reasons had to split into 2 tables

Upvotes: 1

Views: 46

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 89091

In EF6 switch the [Key] to the OrderID property. In EF Core configure it as an alternate key.

Upvotes: 1

Related Questions