private static void DefineApplicationToApplicationModelMapping() { MapperObject.AddMap <Application, ApplicationModel>(src => { var res = new ApplicationModel(); res.InjectFrom(src); res.TenantDomain = src.DomainId; if (src.ToolRelationships != null) { var tools = from t in src.ToolRelationships where t.ApplicationId == src.ApplicationId select new Tool() { ToolId = t.ToolId }; res.Tools = tools.Select(x => MapperObject.Map <Tool, ToolModel>(x)).ToList(); } if (src.AccessoryRelationships != null) { var accessories = from a in src.AccessoryRelationships where a.ApplicationId == src.ApplicationId select new Accessory() { AccessoryId = a.AccessoryId }; res.Accessories = accessories.Select(x => MapperObject.Map <Accessory, AccessoryModel>(x)).ToList(); } return(res); }); }