From a86b432b0c1346e6eb727e2db05a7af6729e4c80 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Mon, 23 Sep 2024 08:33:56 -0700 Subject: [PATCH] fix: NRE in codegen for models with instance methods that lack a PK --- src/IntelliTect.Coalesce/TypeDefinition/MethodViewModel.cs | 6 +++--- src/IntelliTect.Coalesce/Validation/ValidateContext.cs | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/IntelliTect.Coalesce/TypeDefinition/MethodViewModel.cs b/src/IntelliTect.Coalesce/TypeDefinition/MethodViewModel.cs index 53af32794..43d185c90 100644 --- a/src/IntelliTect.Coalesce/TypeDefinition/MethodViewModel.cs +++ b/src/IntelliTect.Coalesce/TypeDefinition/MethodViewModel.cs @@ -177,15 +177,15 @@ public IEnumerable ApiParameters get { var parameters = ClientParameters; - if (IsModelInstanceMethod) + if (IsModelInstanceMethod && Parent.PrimaryKey != null) { parameters = new[] { new ImplicitParameterViewModel( this, - Parent.PrimaryKey!, + Parent.PrimaryKey, "id", - "Primary Key" // TODO: Is this what we want? Also, i18n. + "Primary Key" ) }.Concat(parameters); } diff --git a/src/IntelliTect.Coalesce/Validation/ValidateContext.cs b/src/IntelliTect.Coalesce/Validation/ValidateContext.cs index 321e63817..5e8e8d5c1 100644 --- a/src/IntelliTect.Coalesce/Validation/ValidateContext.cs +++ b/src/IntelliTect.Coalesce/Validation/ValidateContext.cs @@ -123,7 +123,6 @@ public static ValidationHelper Validate(ReflectionRepository repository) if (prop.ReferenceNavigationProperty is not null) { assert.IsNotNull(prop.ReferenceNavigationProperty.Object, "Object property related object not found."); - assert.IsNotNull(prop.ReferenceNavigationProperty.Object?.PrimaryKey, "No primary key on type of this ID's Navigation Property."); } if (prop.Type.IsCollection)