File tree 1 file changed +24
-0
lines changed
src/EntityFrameworkCore.Generator.Core/Templates
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,30 @@ private void GenerateRelationshipMapping(Relationship relationship)
224
224
}
225
225
CodeBuilder . Append ( ")" ) ;
226
226
227
+ var primaryKeys = relationship . PrimaryProperties ;
228
+ var nonPrimaryPrincipalKey = ! primaryKeys
229
+ . Select ( pp => relationship . PrimaryEntity . Properties . ByProperty ( pp . PropertyName ) )
230
+ . All ( p => p . IsPrimaryKey ?? true ) ;
231
+
232
+ if ( nonPrimaryPrincipalKey )
233
+ {
234
+ CodeBuilder . AppendLine ( ) ;
235
+
236
+ CodeBuilder . Append ( ".HasPrincipalKey(t => " ) ;
237
+ if ( primaryKeys . Count > 1 )
238
+ {
239
+ CodeBuilder . Append ( "new { " ) ;
240
+ CodeBuilder . Append ( string . Join ( ", " , primaryKeys . Select ( pp => $ "t.{ pp . PropertyName . ToSafeName ( ) } ") ) ) ;
241
+ CodeBuilder . Append ( " }" ) ;
242
+ }
243
+ else
244
+ {
245
+ var propertyName = primaryKeys . First ( ) . PropertyName . ToSafeName ( ) ;
246
+ CodeBuilder . Append ( $ "t.{ propertyName } ") ;
247
+ }
248
+ CodeBuilder . Append ( ")" ) ;
249
+ }
250
+
227
251
if ( ! string . IsNullOrEmpty ( relationship . RelationshipName ) )
228
252
{
229
253
CodeBuilder . AppendLine ( ) ;
You can’t perform that action at this time.
0 commit comments