I have a squirrely situation, where in some relationships a tables ID
field is used as the key reference. But in other, older implementations, the Name
field was used as the relationship mapping.
FileType:
ID | Name |....
FileTypeDetails:
ID | FileTypeId | ....
PostingGroupDetails :
FileType | ....
PostingGroupDetails.FileType
has a map to FileType.Name
. FileTypeDetails.FileTypeId
maps to FileType.ID
.
I am using the Fluent API structure to do the mappings manually but am running into a wall with this relationship mapping.
I though that doing a multi-key mapping might work but am unsure. Still in the design stage, and about to implement the interface side of the project.
Any ideas on how i make the mapping available to both, until we can consolidate the relationship mapping to one or the other?
EF Implementation:
FileType
I know FileType
is currently Optional, but its only a direct correlation to the Table design. I am flagging it for schema updating, currently in practice it is a required field in order for the entry to be submitted.
ToTable( "FileType" , "Int" );
HasKey( ftd => ftd.ID );
Property( ftd => ftd.ID ).HasColumnName( "ID" )
.HasDatabaseGeneratedOption( DatabaseGeneratedOption.Identity );
Property( ftd => ftd.Name).HasColumnName( "Name" )
.IsOptional();
//Navigation Properties
HasMany( ftd => ftd.FileNames )
.WithRequired( fn => fn.FileType );
HasMany( ftd => ftd.PostingGroupDetails )
.WithRequired( pgd => pgd.FileTypeDetails );
FileNames
FileNames.FileTypeID
relates to FileType.ID
ToTable( "FileNames" , "Int" );
HasKey( fn => fn.ID );
Property( fn => fn.ID ).HasColumnName( "ID" )
.HasDatabaseGeneratedOption( DatabaseGeneratedOption.Identity );
Property( fn => fn.FileTypeID ).HasColumnName( "FileTypeID" )
.IsRequired();
//Navigation Properties
HasRequired( fn => fn.FileType )
.WithMany( ftd => ftd.FileNames )
.HasForeignKey( fn => fn.FileTypeID );
PostingGroupDetails
PostingGroupDetails.FileType
relates to FileType.Name
ToTable( "PostingGroupDetails " , "Int" );
HasKey( pgd => pgd.ID );
Property( pgd => pgd.ID ).HasColumnName( "ID" )
.HasDatabaseGeneratedOption( DatabaseGeneratedOption.Identity );
//Required Properties
Property( pgd => pgd.FileType ).HasColumnName( "FileType" )
.IsRequired();
//Navigation Properties
HasRequired( pgd => pgd.FileTypeDetails )
.WithMany( ftd => ftd.PostingGroupDetails );
Any ideas would be greatly appreciated. Refactoring the Database structure is not an option right now, but it is on the plate to be done.