From 1253a935b7da3c0f575d256f5c350bfcb5cc9d73 Mon Sep 17 00:00:00 2001 From: Alexander B Date: Fri, 12 Apr 2019 11:33:30 +0200 Subject: [PATCH] Added ResolveByPrimaryKey to resolve an object with set primaryKey/s --- Database-Attribute_System/ClassAction.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Database-Attribute_System/ClassAction.cs b/Database-Attribute_System/ClassAction.cs index 11724c5..31dd8fe 100644 --- a/Database-Attribute_System/ClassAction.cs +++ b/Database-Attribute_System/ClassAction.cs @@ -69,7 +69,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] - /// This checks if any class-field and data-attribute does not exists in either (Slower) public static T GetByPrimaryKey(Type classType, object primaryKeyValue, Func>> queryExecutor) where T : new() { Dictionary primaryKeyData = new Dictionary() { }; @@ -115,13 +114,25 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System if (!dataMatchFound) throw new InvalidOperationException($"Cannot create object with primaryKeyData. No data assigned to field '{primaryKeyAtt.parentField.Name}'"); } - string query = QueryBuilder.SelectByPrimaryKey(obj); // Generate query - List> dataSet = queryExecutor(query); // Execute - FillObject(obj, dataSet[0]); // Fill the object + ResolveByPrimaryKey(obj, queryExecutor); return obj; } + /// + /// Resolves dbObject by primaryKey/s + /// Object needs to have primaryKey/s set! + /// + /// + /// Given object (marked with Db-attributes) + /// Function to handle query-calls - Has to return Dictionary[attributeName, attributeValue] + public static void ResolveByPrimaryKey(T classObject, Func>> queryExecutor) + { + string query = QueryBuilder.SelectByPrimaryKey(classObject); // Generate query + List> dataSet = queryExecutor(query); // Execute + FillObject(classObject, dataSet[0]); // Fill the object + } + /// /// Gets a list of dbObjects by attribute/s ///