I am implementing the Fowler’s Accountability Pattern. I have Party with subclasses User, and PeopleGroup. I have Accountability and AccountabilityType. I have Party mapped as a table and User and PeopleGroup both mapped as separate tables. Then lastly there’s an Accountability_Party cross reference table.
So this all works fine, however, here’s the problem.
If I get a peoplegroup and say
pg.ChildAccountablities.Where(x=>x.PartyType == "User")
thus getting all the Parties that are of type User, I can not then cast the Party to a User. This I guess is upcasting.
The reason I need to do this is because I’m using a permissioning system that has an interface on User (IUser) to identify it. I would like to say get all the users assigned to this peoplegroup and give them this permission. But the permissioning system interface requires a class with the IUser interface on it for the assignment and of course Party does not have that
Perhaps I could say something like
_repository.Query<User>(x=>x.ParentAccountabilities.Any(y=>y.Parent == myPeopleGroup))
but that seems like kind of a roundabout way of doing it.
Any thoughts or insights into this problem would be greatly appreciated.
Thanks,
Raif
Update
here is a link to the accountability pattern by Fowler .
Also the code or rather the mappings are as follows
public class PartyMap : DomainEntityMap<Party>
{
public PartyMap()
{
HasManyToMany(x =>x.ParentAccountabilities).Access.CamelCaseField(Prefix.Underscore).LazyLoad();
HasManyToMany(x =>x.ChildAccountabilities).Access.CamelCaseField(Prefix.Underscore).LazyLoad();
}
}
public class PeopleGroupMap : SubclassMap<PeopleGroup>
{
public PeopleGroupMap()
{
Map(x => x.Name);
}
}
public class UserMap : SubclassMap<User>
{
public UserLoginInfoMap()
{
Map(x => x.LoginName);
Map(x => x.Password);
blah blah blah
}
}
public class AccountabilityMap : DomainEntityMap<Accountability>
{
public AccountabilityMap()
{
References(x => x.Parent);
References(x => x.Child);
References(x => x.AccountabilityType);
}
}
public class AccountabilityTypeMap : DomainEntityMap<AccountabilityType>
{
public AccountabilityTypeMap()
{
Map(x => x.Name);
}
}
The DomaineEntityMap is just a map of DomainEntity from which all entities inherit and which has some basic stuff like created date modified date etc.
thx
the code for Accountability would help but i guess it has a Reference to Party which is lazyloaded. NH then creates a proxy deriving from party to represent the lazyloaded party instance. possible solutions