Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Anyone, please help me to define composite primary key on code first, it cannot to define both property code as below

VB
Public Class TaskMapper
    Overridable Property TaskType As TaskType
    Overridable Property Task As Task
End Class

Public Class TaskType
    Inherits MasterData
End Class

Public Class Task
    Inherits MasterData
End Class

Public MustInherit Class MasterData
    Public Property Code() As String
    Public Property Name() As String
    Public Property Status() As String
End Class

Protected Overrides Sub OnModelCreating(ByVal modelBuilder As DbModelBuilder)
     'on this command raised an error  
modelBuilder.Entity(Of TaskMapper).HasKey(Function(tm) New With {tm.Task.Code, tm.TaskType.Code})
End Sub


What I have tried:

Able to define composite primary key
Posted
Updated 5-Jul-16 20:04pm
v2

1 solution

now, I solved this problem already by code as below
Quote:
Public Class TaskMapper
'Public Property ID As Integer
<key,> _
Property TaskTypeCode As String
Overridable Property TaskType As TaskType
<key,> _
Property TaskCode As String
Overridable Property Task As Task
End Class


thank you
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900