Comments (5)
@jbogard Issue still exists. Is this going to be fixed in version 4.1?
from automapper.data.
From @rlaveycal on February 14, 2014 12:36
The problem still exists in version 3.1.1.
It seems to be caused by the IL generated by DataReaderMapper.CreateBuilder(). This enumerates all the columns of the data reader and assigns the value to the corresponding property on the destination type, with no type checking. In cases where the types don't match there should be an override defined as part of the map definition by calling ForMember() so there is no need to attempt the assignment. My solution below uses this assumption to short circuit the IL generation
First add a parameter to CreateBuilder and build a map of the properties that we don't need to assign
private static Build CreateBuilder(Type destinationType, IDataRecord dataRecord, IEnumerable<PropertyMap> propertyMaps)
{
Build builder;
BuilderKey builderKey = new BuilderKey(destinationType, dataRecord);
if (_builderCache.TryGetValue(builderKey, out builder))
{
return builder;
}
HashSet<string> overriddenProperties = new HashSet<string>();
foreach (var map in propertyMaps)
{
overriddenProperties.Add(map.DestinationProperty.Name);
}
Then, check each property in the loop - we can share GetName(i) via a variable.
for (var i = 0; i < dataRecord.FieldCount; i++)
{
string name = dataRecord.GetName(i);
if(overriddenProperties.Contains(name))
continue;
Finally the calls to CreateBuilder() need to have the extra parameter supplied - context.GetContextTypeMap().GetPropertyMaps()
from automapper.data.
Cool, I'll get this in 3.2
On Fri, Feb 14, 2014 at 6:36 AM, rlaveycal [email protected] wrote:
The problem still exists in version 3.1.1.
It seems to be caused by the IL generated by
DataReaderMapper.CreateBuilder(). This enumerates all the columns of the
data reader and assigns the value to the corresponding property on the
destination type, with no type checking. In cases where the types don't
match there should be an override defined as part of the map definition by
calling ForMember() so there is no need to attempt the assignment. My
solution below uses this assumption to short circuit the IL generationFirst add a parameter to CreateBuilder and build a map of the properties
that we don't need to assignprivate static Build CreateBuilder(Type destinationType, IDataRecord dataRecord, IEnumerable<PropertyMap> propertyMaps) { Build builder; BuilderKey builderKey = new BuilderKey(destinationType, dataRecord); if (_builderCache.TryGetValue(builderKey, out builder)) { return builder; } HashSet<string> overriddenProperties = new HashSet<string>(); foreach (var map in propertyMaps) { overriddenProperties.Add(map.DestinationProperty.Name); }
Then, check each property in the loop - we can share GetName(i) via a
variable.for (var i = 0; i < dataRecord.FieldCount; i++) { string name = dataRecord.GetName(i); if(overriddenProperties.Contains(name)) continue;
Finally the calls to CreateBuilder() need to have the extra parameter
supplied - context.GetContextTypeMap().GetPropertyMaps()Reply to this email directly or view it on GitHubhttps://github.com/AutoMapper/AutoMapper/issues/273#issuecomment-35079680
.
from automapper.data.
From @rlaveycal on April 24, 2014 13:40
Hi,
This didn't make 3.2...maybe 3.3?
Thanks
from automapper.data.
Temporary Workaround: In my SQL whenever there is a datatype of int, long, decimal,float, double, I am casting it as a string and then I am creating an explicit .ForMember mapping for those columns. It's painful but works.
from automapper.data.
Related Issues (20)
- AutoMapper v9.0 vs AutoMapper.Data v4.0 HOT 2
- Please provide PDBs HOT 1
- When_mapping_a_data_reader_to_a_dto_with_nullable_enum HOT 2
- Crash when using AddDataReaderMapping HOT 2
- .Map is not working with IDataReader HOT 1
- Mapping data field of DateTimeOffset HOT 3
- IDataReader mapper not applying Custom Type Converter
- [ASP.NET CORE] IDataRecord mapping does not map properties having same name as columns in DataReader HOT 4
- The AutoMapper.Data 4.1.0 is incompatible with AutoMapper 10.0.0. HOT 2
- Opcodes using a short-form index cannot address a local position over 255 HOT 3
- Cannot map an integer DataTable Column in a long Dto property HOT 1
- Not mapping records HOT 1
- AddDataReaderMapping not ignoring recursive class property HOT 1
- how to take DataAnnotations into account? HOT 1
- Error when running in Azure Function, Method not found: AddMemberConfiguration() HOT 1
- AutoMapper 12.0.0 support? HOT 1
- Readme incorrect for initialization HOT 1
- Define generic Type Converter HOT 3
- IDataReader/IDataRecord (snake case) mapped to .NET (Pascal case) via AddDataReaderProfile() not working HOT 2
- AutoMapper 13 Support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from automapper.data.