user1356462
user1356462

Reputation: 11

Mapping use Automapper

How to map List of anonymous to List of T using AutoMapper?

For example:

class Test{
  public string a1{get;set]}
  public string a2{get;set;}
}

//....Entity Framework 4.3.1
var t=from z in db select {z.a1,z.a2};

var tmp=AutoMapper.Mapper.DynamicMap<List<Test>>(t);

But tmp always is empty

How to fix it?

Upvotes: 1

Views: 1108

Answers (2)

Turbot
Turbot

Reputation: 5233

how about you change

var t=from z in db select new Test
                          {
                             a1 = z.a1,
                             a2 = z.a2
                           }

EDIT to allow mapping to dynamic types , you can refer to existing post

Upvotes: 0

bhiku
bhiku

Reputation: 128

You will need to call t.ToList() to execute the query first

var tmp=AutoMapper.Mapper.DynamicMap<List<Test>>(t.ToList());

Upvotes: 1

Related Questions