Skip to content
Open
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
18 changes: 16 additions & 2 deletions src/Dapper.Contrib/SqlMapperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,16 @@ private static List<PropertyInfo> TypePropertiesCache(Type type)
return pis.ToList();
}

var properties = type.GetProperties().Where(IsWriteable).ToArray();
var properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Where(IsWriteable)
.Where(p => !IsPrivate(p))
.ToArray();

if (properties.Length == 0)
{
throw new DataException($"Entity of type '{type.FullName}' has no accessible properties");
}

TypeProperties[type.TypeHandle] = properties;
return properties.ToList();
}
Expand All @@ -141,6 +150,11 @@ private static bool IsWriteable(PropertyInfo pi)
return writeAttribute.Write;
}

private static bool IsPrivate(PropertyInfo pi)
{
return pi.GetGetMethod()?.IsPrivate ?? true;
}

private static PropertyInfo GetSingleKey<T>(string method)
{
var type = typeof(T);
Expand All @@ -156,7 +170,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
}

/// <summary>
/// Returns a single entity by a single id from table "Ts".
/// Returns a single entity by a single id from table "Ts".
/// Id must be marked with [Key] attribute.
/// Entities created from interfaces are tracked/intercepted for changes and used by the Update() extension
/// for optimal performance.
Expand Down