Created
January 29, 2012 22:32
-
-
Save tawman/1701086 to your computer and use it in GitHub Desktop.
PetaPocoHierarchy Organization POCO
This file contains hidden or 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
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