From 75f4709db164784c102ad3042fbdd84f7754f82c Mon Sep 17 00:00:00 2001 From: Railz Date: Mon, 8 Jul 2019 11:57:31 +0200 Subject: [PATCH] Added check if ResolveByPrimaryKey returned any results from database. --- Database-Attribute_System/ClassAction.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Database-Attribute_System/ClassAction.cs b/Database-Attribute_System/ClassAction.cs index 206c3f0..41349c1 100644 --- a/Database-Attribute_System/ClassAction.cs +++ b/Database-Attribute_System/ClassAction.cs @@ -230,6 +230,8 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System { string query = QueryBuilder.SelectByPrimaryKey(classObject); // Generate query List> dataSet = queryExecutor(query); // Execute + + if (dataSet.Count == 0) throw new InvalidOperationException($"Cannot fetch '{typeof(T).Name}' by primary key/s. No results!"); FillObject(classObject, dataSet[0]); // Fill the object } @@ -241,7 +243,6 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System /// Given object (marked with Db-attributes) /// Function to handle query-calls - Has to return Dictionary[attributeName, attributeValue] /// Determents how deep resolving will be executed - /// This checks if any class-field and data-attribute does not exists in either (Slower) public static void ResolveForeignKeys(T classObject, Func>> queryExecutor, int max_depth = 1) where T: new() { Type classType = classObject.GetType();