Skip to content

Commit

Permalink
added some hints
Browse files Browse the repository at this point in the history
  • Loading branch information
DXSdata committed Jan 7, 2020
1 parent 194634d commit c291c62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions MapperTest/Program.cs
Expand Up @@ -14,6 +14,7 @@ static void Main()
//Mapper.Assembly = nameof(MyAlternativeDbContext);

//For more complex types, e.g nested custom objects which AutoMapper cannot determine automatically
//As an alternative, you can also use
//Mapper.CustomMappings.Add(typeof(MyCustomSubclass), typeof(MyCustomSubclassViewModel)); //or:
//Mapper.CustomMappings.Add<MyCustomSubclass, MyCustomSubclassViewModel>();

Expand Down
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -19,8 +19,14 @@ namespace MapperTest
static void Main()
{

//If DB classes reside in other namespace, assembly etc.
//Mapper.Assembly = nameof(MyAlternativeDbContext);
//For more complex types, e.g nested custom objects which AutoMapper cannot determine automatically
//As an alternative, you can also use Attribute Mapping: https://docs.automapper.org/en/latest/Attribute-mapping.html
//Mapper.CustomMappings.Add(typeof(MyCustomSubclass), typeof(MyCustomSubclassViewModel)); //or:
//Mapper.CustomMappings.Add<MyCustomSubclass, MyCustomSubclassViewModel>();
var list1 = new List<MyClass1>
{
new MyClass1(),
Expand All @@ -37,6 +43,7 @@ namespace MapperTest

var dto6 = list1.AsQueryable().ProjectTo<List<MyClass2>>(); //for DB queries
var dto7 = Mapper.ProjectTo<List<MyClass2>>(list1.AsQueryable());



}
Expand All @@ -47,7 +54,12 @@ namespace MapperTest

# Notes

## Nested objects

If you use nested objects, like MyClass1Object.MyClass2Object.Var1, please use the approach "[Attribute Mapping](https://docs.automapper.org/en/latest/Attribute-mapping.html)". Otherwise you will get a "missing maps" error.
You can also use Mapper.CustomMappings (see example above).

### Multiple projects

If the attributed classes are not within your default project assembly, please set Mapper.Assembly manually.

Expand Down

0 comments on commit c291c62

Please sign in to comment.