Created
September 8, 2011 20:16
-
-
Save cbcwebdev/1204550 to your computer and use it in GitHub Desktop.
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
var criteria = session.CreateCriteria<Location>() | |
.Add(Expression.Eq("Heirarchy.Token", token)) | |
.SetFetchMode("Metadata", FetchMode.Eager) | |
.SetFetchMode("Heirarchy.Children", FetchMode.Eager) | |
.SetFetchMode("Heirarchy.Metadata", FetchMode.Eager) | |
.SetResultTransformer(new DistinctRootEntityResultTransformer()); |
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
public class Heirarchy<T> where T : class | |
{ | |
public Heirarchy() | |
{ | |
Children = new List<T>(); | |
} | |
public virtual T Parent | |
{ | |
get; | |
private set; | |
} | |
public virtual IList<T> Children | |
{ | |
get; | |
private set; | |
} | |
public virtual bool IsRoot | |
{ | |
get | |
{ | |
return Parent == null; | |
} | |
} | |
public virtual bool HasChildren | |
{ | |
get | |
{ | |
return Children.Count > 0; | |
} | |
} | |
} |
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
public class Location : Entity | |
{ | |
public Location() | |
{ | |
InitMembers(); | |
} | |
private void InitMembers() | |
{ | |
Heirarchy = new LocationHeirarchy(); | |
Metadata = new List<Metadata>(); | |
} | |
public virtual string Name | |
{ | |
get; | |
set; | |
} | |
public virtual string Route | |
{ | |
get; | |
private set; | |
} | |
public virtual LocationHeirarchy Heirarchy | |
{ | |
get; | |
private set; | |
} | |
public virtual IList<Metadata> Metadata | |
{ | |
get; | |
private set; | |
} | |
} |
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
public class LocationHeirarchy : Heirarchy<Location> | |
{ | |
private string _token; | |
public virtual string Token | |
{ | |
get | |
{ | |
if (string.IsNullOrEmpty(_token)) | |
{ | |
var parent = this.Parent; | |
var tokenString = string.Empty; | |
while (parent != null) | |
{ | |
tokenString += parent.Route; | |
if (parent.Heirarchy.Parent == null) | |
{ | |
tokenString += "/"; | |
} | |
parent = parent.Heirarchy.Parent; | |
} | |
_token = EncyptionUtils.MD5Hash(tokenString); | |
} | |
return _token; | |
} | |
private set | |
{ | |
_token = value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment