Skip to content

Commit 024099c

Browse files
authored
Merge pull request #21 from cajuncoding/bugfix/20-fix_linq_column_attr_nullref_exception
Fix null ref exception with Linq2Db Column name mapping attribute whe…
2 parents 634737e + b31f8e0 commit 024099c

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

NetStandard.SqlBulkHelpers/NetStandard.SqlBulkHelpers.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
<PackageLicenseExpression>MIT</PackageLicenseExpression>
99
<Authors>BBernard / CajunCoding</Authors>
1010
<Company>CajunCoding</Company>
11-
<Version>2.4.4</Version>
11+
<Version>2.4.5</Version>
1212
<PackageProjectUrl>https://github.com/cajuncoding/SqlBulkHelpers</PackageProjectUrl>
1313
<RepositoryUrl>https://github.com/cajuncoding/SqlBulkHelpers</RepositoryUrl>
1414
<Description>A library for easy, efficient and high performance bulk insert and update of data, into a Sql Database, from .Net applications. By leveraging the power of the SqlBulkCopy classes with added support for Identity primary key table columns this library provides a greatly simplified interface to process Identity based Entities with Bulk Performance with the wide compatibility of .NetStandard 2.0.</Description>
1515
<PackageTags>sql server database table bulk insert update identity column sqlbulkcopy orm dapper linq2sql materialization materialized data view materialized-data materialized-view sync replication replica readonly</PackageTags>
1616
<PackageReleaseNotes>
17-
- Fix Collation Conflict Risks -- Thanks to Contribution by @simelis
18-
- Fix Security Vulnerability in System.Data.SqlClient
17+
-Fix Null Reference Exception if Linq2Db Column Attribute is used but no Name mapping is specified since it is actually optional (https://github.com/cajuncoding/SqlBulkHelpers/issues/20).
1918

2019
Prior Relese Notes:
20+
- Fix Collation Conflict Risks -- Thanks to Contribution by @simelis
21+
- Fix Security Vulnerability in System.Data.SqlClient
2122
- Fix Caching bug for Processing Definitions loaded from class Attribute annotations, etc. whereby the FullName was not correctly used resulting in cache conflicts and incorrect values when classes have the same name.
2223
- Add Support to manually control if Materialized Loading tables are cleaned-up/removed when using `SchemaCopyMode.OutsideTransactionAvoidSchemaLocks` via `materializeDataContext.DisableMaterializedStagingTableCleanup()`;
2324
always enabled by default and throws an `InvalidOperationException` if if SchemaCopyMode.InsideTransactionAllowSchemaLocks is used. This provides support for advanced debugging and control flow support.

NetStandard.SqlBulkHelpers/SqlBulkHelper/QueryProcessing/SqlBulkHelpersProcessingDefinition.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,18 @@ protected string GetMappedDbColumnName(PropertyInfo propInfo)
197197
{
198198
var attrAccessor = ObjectAccessor.Create(mappingAttribute);
199199

200+
object attributeNameValue = null;
200201
switch (mappingAttribute.GetType().Name)
201202
{
202203
case MappingAttributeNames.RepoDbFieldMapAttributeName:
203-
return attrAccessor[MappingAttributeNames.RepoDbFieldMapAttributePropertyName].ToString();
204+
attributeNameValue = attrAccessor[MappingAttributeNames.RepoDbFieldMapAttributePropertyName];
205+
break;
204206
case MappingAttributeNames.LinqToDbFieldMapAttributeName:
205-
return attrAccessor[MappingAttributeNames.LinqToDbFieldMapAttributePropertyName].ToString();
206-
default:
207-
return propInfo.Name;
207+
attributeNameValue = attrAccessor[MappingAttributeNames.LinqToDbFieldMapAttributePropertyName];
208+
break;
208209
}
210+
211+
return attributeNameValue?.ToString() ?? propInfo.Name;
209212
}
210213
}
211214
}

SqlBulkHelpers.SampleApp.Common/TestHelpers.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ public TestElementWithMappedNames(TestElement testElement)
123123
[SqlBulkMatchQualifier]
124124
public string MyKey { get; set; }
125125

126+
//TEST case where Name is not Specified in the Linq2Db Column Attribute
127+
// since it is actually Optional: https://github.com/cajuncoding/SqlBulkHelpers/issues/20
128+
[Column()]
129+
public string MyColWithNullName { get; set; }
130+
126131
//Regardless of attribute order the SqlBulkColumn should take precedent!
127132
[Column("INCORRECT_NAME_SHOULD_NOT_RESOLVE")]
128133
[SqlBulkColumn("Value")]

SqlBulkHelpers.Tests/IntegrationTests/SchemaLoadingTests/ProcessingDefinitionTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public void TestProcessDefinitionLoading()
2626
nameof(TestElementWithMappedNames.MyId) => "Id",
2727
nameof(TestElementWithMappedNames.MyKey) => "Key",
2828
nameof(TestElementWithMappedNames.MyValue) => "Value",
29+
//For Test case clarity we explicitly Test Linq2Db Column Attr. with no Name specified: https://github.com/cajuncoding/SqlBulkHelpers/issues/20
30+
nameof(TestElementWithMappedNames.MyColWithNullName) => nameof(TestElementWithMappedNames.MyColWithNullName),
2931
unmappedPropertyName => unmappedPropertyName,
3032
_ => null
3133
};

0 commit comments

Comments
 (0)