@@ -146,6 +146,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
146
146
semanticModel ,
147
147
[ ] , [ ] ) ;
148
148
if ( generationInfo is not { GenType : GenerationType . Class } ) return null ;
149
+ var detectedError = DetectErrors ( generationInfo . Fields . AsSpan ( ) ,
150
+ ( ( InterfaceDeclarationSyntax ) syntaxContext . Node ) . Identifier . GetLocation ( ) ) ;
151
+ if ( detectedError != null )
152
+ return detectedError ;
149
153
return new ( GenerationType . RelationIface , namespaceName , interfaceName ,
150
154
symbol . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) , persistedName , false ,
151
155
false , false ,
@@ -258,6 +262,22 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
258
262
context . RegisterSourceOutput ( gen . Collect ( ) , GenerateCode ! ) ;
259
263
}
260
264
265
+ GenerationInfo ? DetectErrors ( ReadOnlySpan < FieldsInfo > fields , Location location )
266
+ {
267
+ for ( var i = 0 ; i < fields . Length ; i ++ )
268
+ {
269
+ if ( fields [ i ] . Indexes . ToArray ( ) . Any ( ii => ii . Name == null && ii . IncludePrimaryKeyOrder == 1 ) )
270
+ {
271
+ return new ( GenerationType . Error , null , "BTDB0002" ,
272
+ "Cannot use PrimaryKey together with InKeyValue in " + fields [ i ] . Name , null , false , false , false ,
273
+ [ ] ,
274
+ [ ] , [ ] , [ ] , [ ] , [ ] , [ ] , [ ] , location ) ;
275
+ }
276
+ }
277
+
278
+ return null ;
279
+ }
280
+
261
281
static bool IsICovariantRelation ( INamedTypeSymbol typeSymbol )
262
282
{
263
283
// Check if the type is BTDB.ODBLayer.ICovariantRelation<?>
@@ -511,6 +531,7 @@ static bool IsICovariantRelation(INamedTypeSymbol typeSymbol)
511
531
static EquatableArray < IndexInfo > ExtractIndexInfo ( ImmutableArray < AttributeData > attributeDatas )
512
532
{
513
533
var indexInfos = new List < IndexInfo > ( ) ;
534
+ var hasBothPrimaryAndInKeyValue = 0 ;
514
535
foreach ( var attributeData in attributeDatas )
515
536
{
516
537
if ( attributeData . AttributeClass ? . Name == "PrimaryKeyAttribute" )
@@ -519,6 +540,15 @@ static EquatableArray<IndexInfo> ExtractIndexInfo(ImmutableArray<AttributeData>
519
540
var inKeyValue = GetBoolArgForAttributeData ( attributeData , 1 ) ?? false ;
520
541
var primaryKeyAttribute = new IndexInfo ( null , order , inKeyValue , 0 ) ;
521
542
indexInfos . Add ( primaryKeyAttribute ) ;
543
+ hasBothPrimaryAndInKeyValue |= 1 ;
544
+ }
545
+
546
+ if ( attributeData . AttributeClass ? . Name == "InKeyValueAttribute" )
547
+ {
548
+ var order = GetUintArgForAttributeData ( attributeData , 0 ) ?? 0 ;
549
+ var primaryKeyAttribute = new IndexInfo ( null , order , true , 0 ) ;
550
+ indexInfos . Add ( primaryKeyAttribute ) ;
551
+ hasBothPrimaryAndInKeyValue |= 2 ;
522
552
}
523
553
524
554
if ( attributeData . AttributeClass ? . Name == "SecondaryKeyAttribute" )
@@ -531,6 +561,11 @@ static EquatableArray<IndexInfo> ExtractIndexInfo(ImmutableArray<AttributeData>
531
561
}
532
562
}
533
563
564
+ if ( hasBothPrimaryAndInKeyValue == 3 )
565
+ {
566
+ indexInfos . Add ( new ( null , 0 , false , 1 ) ) ;
567
+ }
568
+
534
569
return new ( indexInfos . ToArray ( ) ) ;
535
570
}
536
571
0 commit comments