Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public override void Write(Utf8JsonWriter writer, DatabaseObject value, JsonSeri
// Add TypeName property in DatabaseObject object that we are serializing based on its type. (DatabaseTable, DatabaseView)
// We add this property to differentiate between them in the dictionary. This extra property gets used in deserialization above.
// for example if object is DatabaseTable then we need to add
// "TypeName": "Azure.DataApiBuilder.Config.DatabasePrimitives.DatabaseTable, Azure.DataApiBuilder.Config, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
writer.WriteString(TYPE_NAME, value.GetType().AssemblyQualifiedName);
// "TypeName": "Azure.DataApiBuilder.Config.DatabasePrimitives.DatabaseTable, Azure.DataApiBuilder.Config",
writer.WriteString(TYPE_NAME, GetTypeNameFromType(value.GetType()));

// Add other properties of DatabaseObject
foreach (PropertyInfo prop in value.GetType().GetProperties())
Expand Down Expand Up @@ -75,5 +75,23 @@ private static Type GetTypeFromName(string typeName)

return type;
}

/// <summary>
/// Changes the Type.AssemblyQualifiedName to desired format
/// we cannot use the FullName as during deserialization it throws exception as object not found.
/// </summary>
private static string GetTypeNameFromType(Type type)
{
// AssemblyQualifiedName for the type looks like :
// "Azure.DataApiBuilder.Config.DatabasePrimitives.DatabaseTable, Azure.DataApiBuilder.Config, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
// we donot need version or culture or publickeytoken for serialization or deserialization, we need the first two parts.

string assemblyQualifiedName = type.AssemblyQualifiedName!;
string[] parts = assemblyQualifiedName.Split(',');

// typename would be : "Azure.DataApiBuilder.Config.DatabasePrimitives.DatabaseTable, Azure.DataApiBuilder.Config"
string typeName = $"{parts[0]},{parts[1]}";
return typeName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private void InitializeObjects()

/// <summary>
/// During serialization we add TypeName to the DatabaseObject based on its type. TypeName is the AssemblyQualifiedName for the type.
/// Example : "TypeName": "Azure.DataApiBuilder.Config.DatabasePrimitives.DatabaseTable, Azure.DataApiBuilder.Config, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
/// Example : "TypeName": "Azure.DataApiBuilder.Config.DatabasePrimitives.DatabaseTable, Azure.DataApiBuilder.Config",
/// If there is a code refactor which changes the path of this object, the deserialization with old value will fail, as it wont be able to find the object in the location
/// previously defined.
/// Note : Currently this is being used by GraphQL workload, failure of this test case needs to be
Expand Down Expand Up @@ -367,7 +367,7 @@ private void TestTypeNameChanges(DatabaseObject databaseobject, string objectNam

// Split TypeName into different parts
// following splits different sections of :
// "Azure.DataApiBuilder.Config.DatabasePrimitives.DatabaseTable, Azure.DataApiBuilder.Config, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
// "Azure.DataApiBuilder.Config.DatabasePrimitives.DatabaseTable, Azure.DataApiBuilder.Config"
string[] typeNameSplitParts = typeName.Split(',');

string namespaceString = typeNameSplitParts[0].Trim();
Expand All @@ -376,6 +376,8 @@ private void TestTypeNameChanges(DatabaseObject databaseobject, string objectNam

string projectNameString = typeNameSplitParts[1].Trim();
Assert.AreEqual(projectNameString, "Azure.DataApiBuilder.Config");

Assert.AreEqual(typeNameSplitParts.Length, 2);
}
else
{
Expand Down