public virtual IUmbracoEntity Get(int id, Guid objectTypeId) { bool isContent = objectTypeId == Constants.ObjectTypes.DocumentGuid || objectTypeId == Constants.ObjectTypes.DocumentBlueprintGuid; bool isMedia = objectTypeId == Constants.ObjectTypes.MediaGuid; var sql = GetFullSqlForEntityType(id, isContent, isMedia, objectTypeId); var factory = new UmbracoEntityFactory(); if (isMedia) { //for now treat media differently and include all property data too var entities = _work.Database.Fetch <dynamic, UmbracoPropertyDto, UmbracoEntity>( new UmbracoEntityRelator().Map, sql); return(entities.FirstOrDefault()); } else { //query = read forward data reader, do not load everything into mem var dtos = _work.Database.Query <dynamic>(sql); var collection = new EntityDefinitionCollection(); foreach (var dto in dtos) { collection.AddOrUpdate(new EntityDefinition(factory, dto, isContent, false)); } var found = collection.FirstOrDefault(); return(found != null?found.BuildFromDynamic() : null); } }
public virtual IUmbracoEntity Get(int id, Guid objectTypeId) { bool isContent = objectTypeId == Constants.ObjectTypes.DocumentGuid || objectTypeId == Constants.ObjectTypes.DocumentBlueprintGuid; bool isMedia = objectTypeId == Constants.ObjectTypes.MediaGuid; var sql = GetFullSqlForEntityType(id, isContent, isMedia, objectTypeId); var factory = new UmbracoEntityFactory(); //query = read forward data reader, do not load everything into mem var dtos = UnitOfWork.Database.Query <dynamic>(sql); var collection = new EntityDefinitionCollection(); foreach (var dto in dtos) { collection.AddOrUpdate(new EntityDefinition(factory, dto, isContent, false)); } var found = collection.FirstOrDefault(); return(found != null?found.BuildFromDynamic() : null); }