提交 451d50ba 编写于 作者: M Marc Gravell

1.29: make Underscore_Names opt-in

上级 ce23d47d
......@@ -32,5 +32,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")]
[assembly: AssemblyVersion("1.29.0.0")]
[assembly: AssemblyFileVersion("1.29.0.0")]
......@@ -4678,25 +4678,39 @@ public SqlMapper.IMemberMap GetConstructorParameter(ConstructorInfo constructor,
public SqlMapper.IMemberMap GetMember(string columnName)
{
var property = _properties.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.Ordinal))
?? _properties.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase))
?? _properties.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.Ordinal))
?? _properties.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.OrdinalIgnoreCase));
?? _properties.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase));
if (property == null && MatchNamesWithUnderscores)
{
property = _properties.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.Ordinal))
?? _properties.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.OrdinalIgnoreCase));
}
if (property != null)
return new SimpleMemberMap(columnName, property);
var field = _fields.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.Ordinal))
?? _fields.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase))
?? _fields.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.Ordinal))
?? _fields.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.OrdinalIgnoreCase));
?? _fields.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase));
if (field == null && MatchNamesWithUnderscores)
{
field = _fields.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.Ordinal))
?? _fields.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.OrdinalIgnoreCase));
}
if (field != null)
return new SimpleMemberMap(columnName, field);
return null;
}
/// <summary>
/// Should column names like User_Id be allowed to match properties/fields like UserId ?
/// </summary>
public static bool MatchNamesWithUnderscores { get; set; }
}
/// <summary>
/// Implements custom property mapping by user provided criteria (usually presence of some custom attribute with column to member mapping)
/// </summary>
......
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")]
[assembly: AssemblyVersion("1.29.0.0")]
[assembly: AssemblyFileVersion("1.29.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")]
[assembly: AssemblyVersion("1.29.0.0")]
[assembly: AssemblyFileVersion("1.29.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")]
[assembly: AssemblyVersion("1.29.0.0")]
[assembly: AssemblyFileVersion("1.29.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")]
[assembly: AssemblyVersion("1.29.0.0")]
[assembly: AssemblyFileVersion("1.29.0.0")]
......@@ -17,9 +17,17 @@ public void TestBasicStringUsage()
}
public void TestClassWithStringUsage()
{
var arr = connection.Query<BasicType>("select 'abc' as [Value], '123' as [Another_Value] union all select @txt, @txt2", new { txt = "def", txt2 = "456" }).ToArray();
arr.Select(x => x.Value).IsSequenceEqualTo(new[] { "abc", "def" });
arr.Select(x => x.AnotherValue).IsSequenceEqualTo(new[] { "123", "456" });
var oldMatch = Dapper.DefaultTypeMap.MatchNamesWithUnderscores;
try
{
DefaultTypeMap.MatchNamesWithUnderscores = true;
var arr = connection.Query<BasicType>("select 'abc' as [Value], '123' as [Another_Value] union all select @txt, @txt2", new { txt = "def", txt2 = "456" }).ToArray();
arr.Select(x => x.Value).IsSequenceEqualTo(new[] { "abc", "def" });
arr.Select(x => x.AnotherValue).IsSequenceEqualTo(new[] { "123", "456" });
} finally
{
DefaultTypeMap.MatchNamesWithUnderscores = oldMatch;
}
}
class BasicType
{
......
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")]
[assembly: AssemblyVersion("1.29.0.0")]
[assembly: AssemblyFileVersion("1.29.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")]
[assembly: AssemblyVersion("1.29.0.0")]
[assembly: AssemblyFileVersion("1.29.0.0")]
......@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata schemaVersion="2">
<id>Dapper</id>
<version>1.28</version>
<version>1.29</version>
<title>Dapper dot net</title>
<authors>Sam Saffron,Marc Gravell</authors>
<owners>Sam Saffron,Marc Gravell</owners>
......@@ -19,6 +19,7 @@
<frameworkAssembly assemblyName="Microsoft.CSharp" targetFramework=".NETFramework4.0-Client, .NETFramework4.0" />
</frameworkAssemblies>
<releaseNotes>
* 1.29 - Make underscore name matching optional (opt-in) - this can be a breaking change for some people
* 1.28 - Much better numeric type conversion; fix for large oracle strings; map Foo_Bar to FooBar (etc); ExecuteScalar added; stability fixes
* 1.27 - Fixes for type-handler parse; ensure type-handlers get last dibs on configuring parameters
* 1.26 - New type handler API for extension support
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册