0

I have the following scenario.

public class Foo
{
    public virtual string Name { get; set; }
    public virtual IList<Bar> Bars { get; set; }
}

public class FooDTO
{
     public string Name { get; set; }
     public IList<BarDTO> Bars { get; set; }
}

I ignore the collection Bars

CreateMap<Foo,FooDTO>().ForMember(x => x.Bars, opt => opt.Ignore());

Bars is lazy loading and is mapped with BarsDTO. If i only load the Foo entity from Database I only get the Name value. But when the mapping happens I see in SQL Profiler that all Bars are loaded from Database but are not mapped to DTO.

Why Automapper loads the ignored property?

1
  • A repro would help. Make a gist that we can execute and see fail. Commented Sep 18, 2022 at 6:09

2 Answers 2

1

Lazy loading requires an associated NHibernate ISession open.

Can you send the code of the repository in question that manages the recovery of the data to map DTO

NHibernate proxy lazy loading map to dto object

Sign up to request clarification or add additional context in comments.

Comments

1

Everything works correctly. In FooDTO is another property which is called BarsCount and Automapper maps count automatically. So I have to delete BarsCount from DTO or also ignore it in mapping.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.