Improved Exception messages (variables)
CLassAction: Added GetList Set Version to 1.5.11
This commit is contained in:
		
							parent
							
								
									40936fafcd
								
							
						
					
					
						commit
						8816110211
					
				@ -71,7 +71,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                catch(InvalidOperationException ex)
 | 
					                catch(InvalidOperationException ex)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    throw new InvalidOperationException($"Cannot init foreignObject-field '{fi.Name}' of '{classType.Name}'. {ex.Message}");
 | 
					                    throw new InvalidOperationException($"Cannot init foreignObject-field='{fi.Name}' of class='{classType.Name}'.", ex);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -129,6 +129,31 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // ----
 | 
					        // ----
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets all dbObjects of class/table
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <typeparam name="T"></typeparam>
 | 
				
			||||||
 | 
					        /// <param name="classObject">Given object (marked with Db-attributes)</param>
 | 
				
			||||||
 | 
					        /// <param name="queryExecutor">Function to handle query-calls - Has to return Dictionary[attributeName, attributeValue]</param>
 | 
				
			||||||
 | 
					        public static List<T> GetList<T>(Type classType, Func<string, List<Dictionary<string, object>>> queryExecutor) where T : new()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            // Read dbObject - attribute
 | 
				
			||||||
 | 
					            DbObject dbObject = ClassAction.Init(classType);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            string query = QueryBuilder.SelectByAttribute(dbObject._tableName);   // Generate query
 | 
				
			||||||
 | 
					            List<Dictionary<string, object>> dataSet = queryExecutor(query);    // Execute
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            List<T> objs = new List<T>() { };
 | 
				
			||||||
 | 
					            foreach (Dictionary<string, object> data in dataSet)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                T obj = new T();    // New object
 | 
				
			||||||
 | 
					                FillObject(obj, data);   // Fill it
 | 
				
			||||||
 | 
					                objs.Add(obj);      // Add to list
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return objs;    // Return list
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets an dbObject by primaryKey/s
 | 
					        /// Gets an dbObject by primaryKey/s
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
@ -155,20 +180,6 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
 | 
				
			|||||||
            return objs;    // Return list
 | 
					            return objs;    // Return list
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// Resolves dbObject by primaryKey/s<pragma/>
 | 
					 | 
				
			||||||
        /// Object needs to have primaryKey/s set!
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        /// <typeparam name="T"></typeparam>
 | 
					 | 
				
			||||||
        /// <param name="classObject">Given object (marked with Db-attributes)</param>
 | 
					 | 
				
			||||||
        /// <param name="queryExecutor">Function to handle query-calls - Has to return Dictionary[attributeName, attributeValue]</param>
 | 
					 | 
				
			||||||
        public static void ResolveByPrimaryKey<T>(T classObject, Func<string, List<Dictionary<string, object>>> queryExecutor)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            string query = QueryBuilder.SelectByPrimaryKey(classObject);   // Generate query
 | 
					 | 
				
			||||||
            List<Dictionary<string, object>> dataSet = queryExecutor(query);    // Execute
 | 
					 | 
				
			||||||
            FillObject(classObject, dataSet[0]);   // Fill the object
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets a list of dbObjects by attribute/s
 | 
					        /// Gets a list of dbObjects by attribute/s
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
@ -199,7 +210,21 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
 | 
				
			|||||||
            return objs;    // Return list
 | 
					            return objs;    // Return list
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // -----
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Resolves dbObject by primaryKey/s<pragma/>
 | 
				
			||||||
 | 
					        /// Object needs to have primaryKey/s set!
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <typeparam name="T"></typeparam>
 | 
				
			||||||
 | 
					        /// <param name="classObject">Given object (marked with Db-attributes)</param>
 | 
				
			||||||
 | 
					        /// <param name="queryExecutor">Function to handle query-calls - Has to return Dictionary[attributeName, attributeValue]</param>
 | 
				
			||||||
 | 
					        public static void ResolveByPrimaryKey<T>(T classObject, Func<string, List<Dictionary<string, object>>> queryExecutor)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            string query = QueryBuilder.SelectByPrimaryKey(classObject);   // Generate query
 | 
				
			||||||
 | 
					            List<Dictionary<string, object>> dataSet = queryExecutor(query);    // Execute
 | 
				
			||||||
 | 
					            FillObject(classObject, dataSet[0]);   // Fill the object
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Resolves all foreignKeys with the database<pragma/>
 | 
					        /// Resolves all foreignKeys with the database<pragma/>
 | 
				
			||||||
@ -224,7 +249,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
 | 
				
			|||||||
                // When its empty, get it
 | 
					                // When its empty, get it
 | 
				
			||||||
                if(foreignObject_value == null)
 | 
					                if(foreignObject_value == null)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    foreignObject_value = GetByPrimaryKey<T>(classType, foreignObjectAtt.foreignKeyAttribute.parentField.GetValue(classObject), queryExecutor); ;
 | 
					                    foreignObject_value = GetByPrimaryKey<T>(classType, foreignObjectAtt.foreignKeyAttribute.parentField.GetValue(classObject), queryExecutor);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // Recursive resolving
 | 
					                // Recursive resolving
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,7 @@
 | 
				
			|||||||
    <TargetFramework>netcoreapp2.1</TargetFramework>
 | 
					    <TargetFramework>netcoreapp2.1</TargetFramework>
 | 
				
			||||||
    <RootNamespace>eu.railduction.netcore.dll.Database_Attribute_System</RootNamespace>
 | 
					    <RootNamespace>eu.railduction.netcore.dll.Database_Attribute_System</RootNamespace>
 | 
				
			||||||
    <SignAssembly>false</SignAssembly>
 | 
					    <SignAssembly>false</SignAssembly>
 | 
				
			||||||
    <Version>1.5.9</Version>
 | 
					    <Version>1.5.11</Version>
 | 
				
			||||||
  </PropertyGroup>
 | 
					  </PropertyGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</Project>
 | 
					</Project>
 | 
				
			||||||
 | 
				
			|||||||
@ -68,6 +68,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            string sqlCmd = $"SELECT * FROM {tableName}";
 | 
					            string sqlCmd = $"SELECT * FROM {tableName}";
 | 
				
			||||||
            // Add SQL-command part
 | 
					            // Add SQL-command part
 | 
				
			||||||
 | 
					            if (!(whereClause[0] is string)) throw new InvalidOperationException("Cannot generate SQL-query. WhereClause-params not starting with string!");
 | 
				
			||||||
            whereClause[0] = $"{sqlCmd} WHERE {whereClause[0]}";
 | 
					            whereClause[0] = $"{sqlCmd} WHERE {whereClause[0]}";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Build and return the query
 | 
					            // Build and return the query
 | 
				
			||||||
 | 
				
			|||||||
@ -95,7 +95,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (!nameFound) throw new InvalidOperationException($"{attributeNameAndValue.Key} has no classField!");
 | 
					                if (!nameFound) throw new InvalidOperationException($"'{attributeNameAndValue.Key}' has no classField!");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        internal static void ConvertAttributeToDbAttributes(Type classType, List<string> attributeNames)
 | 
					        internal static void ConvertAttributeToDbAttributes(Type classType, List<string> attributeNames)
 | 
				
			||||||
@ -117,7 +117,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (!nameFound) throw new InvalidOperationException($"{attributeNames[i]} has no classField!");
 | 
					                if (!nameFound) throw new InvalidOperationException($"'{attributeNames[i]}' has no classField!");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -141,7 +141,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
 | 
				
			|||||||
                DateTime dateTime = (DateTime)obj;
 | 
					                DateTime dateTime = (DateTime)obj;
 | 
				
			||||||
                return "'" + SqlSerialise(dateTime) + "'";     // wrap in sql-brackets and convert to sql-datetime
 | 
					                return "'" + SqlSerialise(dateTime) + "'";     // wrap in sql-brackets and convert to sql-datetime
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (obj.GetType() == typeof(Guid))        // Handle DateTime
 | 
					            else if (obj.GetType() == typeof(Guid))        // Handle Guid
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                string guid = ((Guid)obj).ToString();  // Get Guid as string
 | 
					                string guid = ((Guid)obj).ToString();  // Get Guid as string
 | 
				
			||||||
                return "'" + guid + "'";                 // wrap in sql-brackets
 | 
					                return "'" + guid + "'";                 // wrap in sql-brackets
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user