tags:

views:

28

answers:

2

i have an object named party and three other objects inherit from this object, using hibernate az orm i have a problem with casting the party to ine of these objects. although i'm using not.lazyload() feature, but i see partyProxy want to be casted to department object , not exact party object . so i see: Unable to cast object of type 'PartyProxybc26f81f729145c49bc14594bb84cb57' to type 'Domain.OrganizationStructure.Department' this problem wont happen to those 2 other objects which are inherited from party object. what could be my problem

A: 

PartyProxy would be a subclass of Party. You are probably trying to assign it to a variable of type Department. It would be helpful if you share snippets of the code/mapping

Sriram
A: 

here is the code i'm using :

public class AccountabilityMap : ClassMap { public AccountabilityMap() { Schema("organizationstructure"); Not.LazyLoad(); Id(p => p.Id);

        References(p => p.AccountabilityType)
            .Not.Nullable();

        References(p => p.Child)
            .Column("ChildPartyId")
            .Not.LazyLoad()
            .Not.Nullable();

        References(p => p.Parent)
            .Column("ParentPartyId")
            .Not.LazyLoad()
            .Not.Nullable();
    }
} 

public class PartyMap : ClassMap { public PartyMap() { Schema("organizationstructure");

        Id(p => p.Id);

HasMany(p => p.Children) .LazyLoad() .Cascade.AllDeleteOrphan() .Inverse() .KeyColumn("ParentPartyId");

        HasMany(p => p.Parents)
            .LazyLoad()
            .Inverse()
            .Cascade.AllDeleteOrphan()
            .KeyColumn("ChildPartyId");

} }

public class DepartmentMap : SubclassMap { public DepartmentMap() {

        Schema("organizationstructure");
        KeyColumn("PartyId");

        Map(p => p.DepartmentType)
            .Not.Nullable()
            .CustomSqlType("tinyint")
            .CustomType<DepartmentType>()
            .Length(1);

        HasManyToMany(p => p.DepartmentGroup)
            .Table("DepartmentGroupToDepartment")
            .Schema("formation");

   }
}

fetching the departments: _department = Parents // =====> parents:IList .Where(p => p.AccountabilityType.Id == (int)AccountabilityTypeDbId.ParentDepartmentOfPerson) .Select(p => p.Parent) .Cast() .SingleOrDefault();

adrakadabra
please add this to the original question.
Mauricio Scheffer