diff --git a/Database-Attribute_System/Database-Attribute_System.csproj b/Database-Attribute_System/Database-Attribute_System.csproj
index f651dc5..38121cf 100644
--- a/Database-Attribute_System/Database-Attribute_System.csproj
+++ b/Database-Attribute_System/Database-Attribute_System.csproj
@@ -3,6 +3,7 @@
netcoreapp2.1eu.railduction.netcore.dll.Database_Attribute_System
+ false
diff --git a/Database-Attribute_System/QueryBuilder.cs b/Database-Attribute_System/QueryBuilder.cs
index 5ee0e4f..796c42d 100644
--- a/Database-Attribute_System/QueryBuilder.cs
+++ b/Database-Attribute_System/QueryBuilder.cs
@@ -25,39 +25,38 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
public static string SelectByPrimaryKeys(Type classType, params object[] comparisonValues)
{
// Check if class has attribute 'DbObject' and get the database table-name
- DbObject dbObjectAttribute = classType.GetCustomAttribute(typeof(DbObject), true) as DbObject;
- if (dbObjectAttribute == null) throw new InvalidOperationException("Cannot generate SQL-Query of class. Missing Attribute 'DbObject'");
+ if (!(classType.GetCustomAttribute(typeof(DbObject), true) is DbObject dbObjectAttribute)) throw new InvalidOperationException("Cannot generate SQL-Query of class. Missing Attribute 'DbObject'");
string tableName = dbObjectAttribute._tableName ?? dbObjectAttribute._tableName; // If no alternative table-name is specified, use the class-name
// Iterate thru all properties
List dbPrimaryKeys = new List() { };
- foreach (System.Reflection.PropertyInfo pi in classType.GetProperties())
+ foreach (System.Reflection.FieldInfo fi in classType.GetRuntimeFields())
{
// Get primaryKey attribute from current property
- DbPrimaryKey pkey = pi.GetCustomAttribute(typeof(DbPrimaryKey) ,true) as DbPrimaryKey;
- if(pkey != null)
+ if (fi.GetCustomAttribute(typeof(DbPrimaryKey), true) is DbPrimaryKey pkey)
{
- string dbAttributeName = pkey._attributeName ?? pi.Name; // If no alternative attribute-name is specified, use the property-name
+ string dbAttributeName = pkey._attributeName ?? fi.Name; // If no alternative attribute-name is specified, use the property-name
dbPrimaryKeys.Add(dbAttributeName);
}
}
- if (comparisonValues.Length != dbPrimaryKeys.Count)
- throw new InvalidOperationException("Primary-key number of class/table and number of comparison values is not equal!");
+ if (comparisonValues.Length != dbPrimaryKeys.Count) throw new InvalidOperationException("Primary-key number of class/table and number of comparison values is not equal!");
- object[] whereParams = new object[comparisonValues.Length*2];
- for (int i=0,c=0; c 0) sql_string += " AND ";
+ if (i == 0) sql_string += $"SELECT * FROM {tableName} WHERE ";
+ else sql_string += " AND ";
sql_string += $"{dbPrimaryKeys[i]}=";
- whereParams[c] = sql_string;
- whereParams[c+1] = comparisonValues[i];
+ param[c] = sql_string;
+ param[c + 1] = comparisonValues[i];
}
- return BuildQuery($"SELECT * FROM {tableName} WHERE ", whereParams);
+ return BuildQuery(param);
}
@@ -69,38 +68,53 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
/// Example: "SELECT * FROM table WHERE id=", id, " AND name=", name
public static string BuildQuery(params object[] param)
{
+ // Convert array to list and add object[] to it accordingly
+ List