3 Commits
v1.5 ... v1.5.5

Author SHA1 Message Date
Alexander B
d6337ef591 Ser version 2019-04-12 11:39:25 +02:00
Alexander B
1253a935b7 Added ResolveByPrimaryKey to resolve an object with set primaryKey/s 2019-04-12 11:33:30 +02:00
Railz
2d4a4d5f7e Changed DbForeignObject no longer needing the Type 2019-04-10 23:07:12 +02:00
3 changed files with 20 additions and 10 deletions

View File

@@ -9,7 +9,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes
[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
public class DbForeignObject : Attribute
{
public Type _foreignObjectType;
public Type foreignObjectType;
public string _foreignKeyName;
public DbForeignKey foreignKeyAttribute;
@@ -20,11 +20,9 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes
/// <summary>
/// Marks variable as foreign-object of an dbObject
/// </summary>
/// <param name="foreignObjectType">Type of foreignObject</param>
/// <param name="foreignKeyName">Fieldname of foreignKey associated with the foreignObject</param>
public DbForeignObject(Type foreignObjectType, string foreignKeyName = null)
public DbForeignObject(string foreignKeyName = null)
{
this._foreignObjectType = foreignObjectType;
this._foreignKeyName = foreignKeyName;
}
@@ -32,9 +30,10 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes
{
this.parentField = fi;
this.classAttribute = classAttribute;
this.foreignObjectType = fi.GetType();
// Init foreign-object class
DbObject foreignClassAttribute = ClassAction.Init(this._foreignObjectType);
DbObject foreignClassAttribute = ClassAction.Init(this.foreignObjectType);
// Check if something is weird
if (foreignClassAttribute.primaryKeyAttributes.Count < 1) throw new InvalidOperationException($"'{foreignClassAttribute.parentClassType.Name}' does not have a primaryKey.");

View File

@@ -69,7 +69,6 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
/// <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>
/// <param name="runDataLossChecks">This checks if any class-field and data-attribute does not exists in either (Slower)</param>
public static T GetByPrimaryKey<T>(Type classType, object primaryKeyValue, Func<string, List<Dictionary<string, object>>> queryExecutor) where T : new()
{
Dictionary<string, object> primaryKeyData = new Dictionary<string, object>() { };
@@ -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<Dictionary<string, object>> dataSet = queryExecutor(query); // Execute
FillObject(obj, dataSet[0]); // Fill the object
ResolveByPrimaryKey<T>(obj, queryExecutor);
return obj;
}
/// <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>
/// Gets a list of dbObjects by attribute/s
/// </summary>

View File

@@ -4,7 +4,7 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>eu.railduction.netcore.dll.Database_Attribute_System</RootNamespace>
<SignAssembly>false</SignAssembly>
<Version>1.5</Version>
<Version>1.5.5</Version>
</PropertyGroup>
</Project>