Many-to-any If the table structure is fixed, and you want to use the identity id generator, I would map the Source tables as 3 separate classes and map to the common interface as an any reference class Case { public virtual IReferral Referral { get; set; } } class SourceA : IReferral { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual string Type { get { return "SourceA"; } } } interface IReferral { int Id { get; set; } string Name { get; set; } string Type { get; } } public class CaseMap : ClassMap { public CaseMap() { ReferencesAny(m => m. Referral) . EntityTypeColumn("ReferralType") .
EntityIdentifierColumn("ReferralId") . AddMetaValue("SourceA") . AddMetaValue("SourceB") .
AddMetaValue("SourceC") .IdentityType(); } } union-subclass Another option is union-subclass with an abstract base class mapping. This allows eager fetching, but you cannot use the identity generator on the subclass tables class name="IReferral" abstract="true" table="Referral".
Many-to-any If the table structure is fixed, and you want to use the identity id generator, I would map the Source tables as 3 separate classes and map to the common interface as an any reference. Class Case { public virtual IReferral Referral { get; set; } } class SourceA : IReferral { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual string Type { get { return "SourceA"; } } } interface IReferral { int Id { get; set; } string Name { get; set; } string Type { get; } } public class CaseMap : ClassMap { public CaseMap() { ReferencesAny(m => m. Referral) .
EntityTypeColumn("ReferralType") . EntityIdentifierColumn("ReferralId") . AddMetaValue("SourceA") .
AddMetaValue("SourceB") . AddMetaValue("SourceC") .IdentityType(); } } union-subclass Another option is union-subclass with an abstract base class mapping. This allows eager fetching, but you cannot use the identity generator on the subclass tables.
Subclass If you can change the tables, you can map all 3 Referral classes to the same table using subclass.
I can't seem to get your sample working. I'm getting a "Not a member access Parameter name: expression" error – Mark Boltuc Mar 17 '10 at 3:03 I managed to get it working (see my answer). Thanks for the help Lachlan.
– Mark Boltuc Mar 17 '10 at 16:19.
ReferralId { get; protected set; } public virtual string Name { get { return null; } //NOTE: We need this for mapping reasons protected virtual int CaseId { get; set; } protected CaseReferral() { } } public class CaseSourceAReferral : CaseReferral { private SourceA _sourceA; public virtual SourceA Source { get { return _sourceA; } protected set { _sourceA = value; Type = "SourceA"; ReferralId = ( _sourceA! = null? _sourceA.
Id : null ); } } public override string Name { get { return Source.Name; } } //NOTE: Default constructor for mapping reasons protected CaseSourceAReferral() { } public CaseSourceAReferral( int caseId, SourceA source ) { CaseId = caseId; Source = source; } } public class CaseMap : ClassMap { public CaseMap() { Id( c => c. Id ); References( c => c. Referral ).
Column( "Id" ); } } public class CaseReferralMap : ClassMap { public CaseReferralMap() { Id( Reveal. Property( "CaseId") ). Column( "Id" ); Map( r => r.
Type ). Column( "ReferralType" ); Map( r => r. ReferralId ).
Column( "ReferralId" ); DiscriminateSubClassesOnColumn( "ReferralType" ); } } public class CaseSourceAReferralMap : SubclassMap { public CaseSourceAReferralMap() { DiscriminatorValue( "SourceA" ); References( r => r. Source ). Column( "ReferralId" ); } }.
I need help in configuring log4net and Fluent NHibernate. It seems log4net is starting, but I'm not getting any information from NHibernate/Fluent NHibernate. I want this information to debug faulty mapping.
Configuration in App. Here's how I launch log4net and configuration.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.