0

I have 2 classes at the moment. The first is an asset, the second is services associated with that asset. The Asset table in SQL Server has a PK over both ID and workflow_id.

public class Asset
{
    public int ID { get; set; }
    public int workflow_id { get; set; }

    public string name { get; set; }
}

The second table is services which has a PK over the 3 columns, the service ID, workflow_id and the asset_id the service is tied too.

public class Services
{
    public int ID { get; set; }
    public int workflow_id { get; set; }
    public int asset_id { get; set; }

    public string service_description { get; set; }
}

Example Data: Asset with ID#10 in workflow_id#27 matches all the Services with asset_id#10 in workflow_id#27.

How can I map these two together with the multi-column PKs?

Alex.Ritna
  • 1,957
  • 2
  • 16
  • 24

1 Answers1

1

Annotate the columns that you want to be PK's. In your example for the first model you would have:

    [Key, System.ComponentModel.DataAnnotations.Schema.Column(Order = 0)]
    public int ID { get; set; }


    [Key, System.ComponentModel.DataAnnotations.Schema.Column(Order = 1)]
    public int workflow_id { get; set; }
Steve Sloka
  • 3,444
  • 2
  • 22
  • 29