{"issue":{"state":"open","created_at":"2011-12-04T10:00:07Z","updated_at":"2011-12-04T10:00:07Z","comments":0,"user":{"gravatar_id":"0413bc647d177bdf8281f0628f4a3b5c","id":343373,"url":"https://api.github.com/users/noir2501","avatar_url":"https://secure.gravatar.com/avatar/0413bc647d177bdf8281f0628f4a3b5c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"noir2501"},"body":"I am struggling with this issue:\r\n\r\nI have a list of NHibernate objects called \"Project\". These objects contain a lazy - loaded list of \"Branches\". I am trying to pass a list of Projects to a WCF service so I am using AutoMapper to transform them to flat objects.\r\n\r\nThe problem is that even though the destination objects called \"ProjectContract\" does not contain a list of Branches, Automapper still invokes this collection and a lot of queries are made to the database because NHibernate fires the lazy - loading and loads the Branches collection for each project.\r\n\r\nHere are the classes and the mapping:\r\n\r\n```C#\r\n  public class Project\r\n    {\r\n     public virtual int ID\r\n     {\r\n        get;\r\n        set;\r\n     }\r\n\r\n     public virtual string Name { get; set; }\r\n     public virtual string Description { get; set; }\r\n\r\n     public virtual IList<Branch> Branches { get; set; }\r\n    }\r\n\r\n  [DataContract]\r\n  public class ProjectContract\r\n  {\r\n    [DataMember]\r\n    public virtual int ID\r\n    {\r\n        get;\r\n        set;\r\n    }\r\n\r\n    [DataMember]\r\n    public virtual string Name { get; set; }\r\n\r\n    [DataMember]\r\n    public virtual string Description { get; set; }\r\n  }\r\n\r\n  public class ProjectMappings : Profile\r\n  {\r\n    protected override void Configure()\r\n    {\r\n        Mapper.CreateMap<Project, ProjectContract>();\r\n    }\r\n  }\r\n```\r\n\r\nMy question is: Is there a way to tell AutoMapper to not touch the \"Branches\" collection because I don't care about it and that is a proxy that will trigger many database calls?\r\n\r\nI temporarily fixed this with MaxDepth(1), but there are other entities where I have collections that I want to transfer, and collections that I don't want to be touched, like this one. In that case, MaxDepth(0) will not work.","assignee":null,"id":2441321,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"number":155,"labels":[],"title":"Automapper triggers NHibernate lazy loading on properties not used in destination","html_url":"https://github.com/AutoMapper/AutoMapper/issues/155","closed_at":null,"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/155","milestone":null},"action":"opened"}