Skip to content

Instantly share code, notes, and snippets.

@tawman
Created January 29, 2012 22:32
Show Gist options
  • Save tawman/1701086 to your computer and use it in GitHub Desktop.
Save tawman/1701086 to your computer and use it in GitHub Desktop.
PetaPocoHierarchy Organization POCO
using System;
using System.Linq;
using System.Collections.Generic;
using PetaPoco;
namespace PetaPocoHierarchy.Models
{
public class Organization
{
public Guid Id { get; set; }
public Guid ParentId { get; set; }
public string OrganizationCode { get; set; }
public string Name { get; set; }
[Ignore]
public Organization Parent { get; set; }
[Ignore]
public string Hierarchy
{
get { return string.Join(" › ", GetHierarchy().Select(x => x.Name)); }
}
public IEnumerable<Organization> GetHierarchy()
{
if (Parent == null)
{
yield return this;
}
else
{
foreach (var ancestor in Parent.GetHierarchy())
{
yield return ancestor;
}
yield return this;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment