Created
November 20, 2014 10:51
-
-
Save jbreuer/a396f1e4504e181e1c8a to your computer and use it in GitHub Desktop.
Strongly typed querying in Umbraco
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Return the all the data required for filtering and displaying object types. | |
/// </summary> | |
/// <returns></returns> | |
public static IEnumerable<ObjectTypeItem> GetObjectTypeItems() | |
{ | |
//Get the node where all projects and object types are below. | |
var projectOverview = Umbraco.TypedContent(ConfigurationManager.AppSettings["projectOverviewId"]); | |
return | |
( | |
from project in projectOverview.Children<ProjectDetails>() | |
from objectType in project.Children<ObjectTypeDetails>() | |
let city = project.City | |
select new ObjectTypeItem() | |
{ | |
ObjectType = objectType.DocumentTypeAlias.EnumParse<ObjectType>(true), | |
ProjectStatus = project.Status, | |
ObjectTypeTitle = objectType.Title, | |
ProjectTitle = project.Title, | |
CityTitle = city.Title, | |
FromPrice = objectType.FromPrice, | |
FromPriceExtra = objectType.FromPriceExtra, | |
TillPrice = objectType.TillPrice, | |
TillPriceExtra = objectType.TillPriceExtra, | |
NumberAvailable = objectType.NumberAvailable, | |
Location = project.Location, | |
Images = objectType.HeaderVisuals, | |
Url = objectType.Url | |
} | |
).ToList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Shazwazza What if it was instantiated inside the static method? I mean, I use static methods all the time but I'm doing something like this:
var h = ContentHelper.GetHelper();
And this one is a method that @Nicholas-Westby was so kind to share with me - you can find it here: https://github.com/rhythmagency/rhythm.umbraco.extensions/blob/56a328f8c84d4f155d7201494be62ecfb0aaf32e/trunk/Rhythm.Extensions/Rhythm.Extensions/Helpers/ContentHelper.cs#L27 - it ensures that only one UmbracoHelper gets instantiated per HTTP request. But, even without that, why ditch statics all together and not just instantiate an UmbracoHelper?