Mapping class to record result in empty properties
See original GitHub issueHi, If you try to map from class object to record type, the result is a new record with empty properties. For example :
source class :
public class DAO
{
public string name { get; set; }
public string code { get; set; }
}
destination record :
public record DTO
{
string name;
string code;
public DTO(string _name, string _code)
{
name = _name;
code = _code;
}
}
mapping :
var dao = new DAO() { name = "test", code = "test" };
var dto = dao.Adapt<DTO>();
dto object contains all properties empty.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Mapping property with underscore to record with constructor
Mapping MyEntity to MyDTO works fine, as expected. However, when mapping to MyDTOWithConstructor the Some_Value property is not mapped. I have ...
Read more >Empty property value after Automapper v5 upgrade
I have setup the mappings in AutoMapper for all 4 classes and then I call Map. The result is that the after the...
Read more >Records - C# reference
Positional properties are immutable in a record class and a readonly ... Those properties /// map to the JSON elements "firstName" and ...
Read more >Using the Record Mapper | Developing Productions
The properties in the generated record class are dependent on the names of the fields in the record map.
Read more >c# - Generic Null/Empty check for each property of a class
My starting point is the IsNullOrEmpty method, which is invoked against any property in the tree of properties of any specified complex object...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I believe I’m seeing the same issue here.
Mapping to this class works:
But if I try to shorten the code and map to a C# 9.0 record, it doesn’t work anymore:
When I map to the record,
Idis correctly mapped, butNAMEis ignored. It staysnulland is completely absent from theProjectToexpression.Fixed in #590