Skip to content

Commit

Permalink
Merge pull request #665 from mikependon/repodb-fixes
Browse files Browse the repository at this point in the history
#662 Fixes on the F# Immutable Type Mapping
  • Loading branch information
mikependon authored Dec 4, 2020
2 parents 615d47f + d7b6efb commit 740d80d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,6 @@ public void TestSqlConnectionInsertForMappedPropertiesImmutable()

// Assert
Assert.IsTrue(insertResult > 0);
Assert.AreEqual(insertResult, entity.Id);
}
}

Expand All @@ -1382,9 +1381,6 @@ public void TestSqlConnectionInsertAllForMappedPropertiesImmutable()
// Assert
Assert.AreEqual(entities.Count, insertAllResult);
Assert.AreEqual(entities.Count, connection.CountAll<MappedPropertiesImmutableIdentityTable>());

// Assert
Assert.IsTrue(entities.All(e => e.Id > 0));
}
}

Expand Down Expand Up @@ -1473,9 +1469,6 @@ public void TestSqlConnectionMergeAllForMappedPropertiesImmutable()
Assert.AreEqual(entities.Count, mergeAllRequest);
Assert.AreEqual(entities.Count, connection.CountAll<MappedPropertiesImmutableIdentityTable>());

// Assert
Assert.IsTrue(entities.All(e => e.Id > 0));

// Act
var queryResult = connection.QueryAll<MappedPropertiesImmutableIdentityTable>().AsList();

Expand Down
49 changes: 30 additions & 19 deletions RepoDb.Core/RepoDb/Reflection/Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ internal class ClassPropertyParameterInfo
/// </summary>
public ParameterInfo ParameterInfo { get; set; }

/// <summary>
/// Gets the instance of <see cref="RepoDb.ClassProperty"/> object that is mapped to the current <see cref="ParameterInfo"/>.
/// </summary>
public ClassProperty ParameterInfoMappedClassProperty { get; set; }

/// <summary>
/// Gets the target type.
/// </summary>
Expand Down Expand Up @@ -1153,35 +1158,40 @@ internal static IEnumerable<ClassPropertyParameterInfo> GetClassPropertyParamete
// Class properties
var classProperties = PropertyCache
.Get(typeOfResult)?
.Where(property => property.PropertyInfo.CanWrite)
//.Where(property => property.PropertyInfo.CanWrite)
.Where(property =>
readerFieldsName?.FirstOrDefault(field =>
string.Equals(field.AsUnquoted(true, dbSetting), property.GetMappedName().AsUnquoted(true, dbSetting), StringComparison.OrdinalIgnoreCase)) != null)
.AsList();

// ParameterInfos
parameterInfos?.ForEach(parameterInfo =>
{
var classProperty = classProperties?.
FirstOrDefault(item =>
string.Equals(item.PropertyInfo.Name, parameterInfo.Name, StringComparison.OrdinalIgnoreCase));
list.Add(new ClassPropertyParameterInfo
parameterInfos?
.ForEach(parameterInfo =>
{
ClassProperty = classProperty,
ParameterInfo = parameterInfo
var classProperty = classProperties?.
FirstOrDefault(property =>
string.Equals(property.PropertyInfo.Name, parameterInfo.Name, StringComparison.OrdinalIgnoreCase));
list.Add(new ClassPropertyParameterInfo
{
ClassProperty = classProperty.PropertyInfo.CanWrite ? classProperty : null,
ParameterInfo = parameterInfo,
ParameterInfoMappedClassProperty = classProperty
});
});
});

// ClassProperties
classProperties.ForEach(classProperty =>
{
var listItem = list.FirstOrDefault(item => item.ClassProperty == classProperty);
if (listItem != null)
classProperties
.Where(property => property.PropertyInfo.CanWrite)
.AsList()
.ForEach(property =>
{
return;
}
list.Add(new ClassPropertyParameterInfo { ClassProperty = classProperty });
});
var listItem = list.FirstOrDefault(item => item.ClassProperty == property);
if (listItem != null)
{
return;
}
list.Add(new ClassPropertyParameterInfo { ClassProperty = property });
});

// Return the list
return list;
Expand Down Expand Up @@ -1215,7 +1225,8 @@ internal static IEnumerable<MemberBinding> GetMemberBindingsForDataEntity<TResul
// Iterate each properties
foreach (var classPropertyParameterInfo in classPropertyParameterInfos)
{
var mappedName = classPropertyParameterInfo.ParameterInfo?.Name.AsUnquoted(true, dbSetting) ??
var mappedName = classPropertyParameterInfo.ParameterInfoMappedClassProperty?.GetMappedName().AsUnquoted(true, dbSetting) ??
classPropertyParameterInfo.ParameterInfo?.Name.AsUnquoted(true, dbSetting) ??
classPropertyParameterInfo.ClassProperty?.GetMappedName().AsUnquoted(true, dbSetting);

// Skip if not found
Expand Down

0 comments on commit 740d80d

Please sign in to comment.