I have a legacy database mapping issue. The database is storing all of its
lookup values (code/description) in one table, distinguished by a type code
field. The tables referring to it do so with one column (the code, without
the type code). The code table does not have a primary key constraint (!).
I have a class that looks like this:
public class Code
{
[StringLength(8)]
public virtual string CodeValue { get; set; }
[StringLength(2000)]
public virtual string Description { get; set; }
public virtual long? OrderBy { get; set; }
public virtual DateTime? StopDate { get; set; }
}
My initial mapping looked like this:
public class CodesMap : ClassMap<Code>
{
public CodesMap()
{
Table("CODES");
Id(x => x.CodeValue).Column("CODE_CODE").GeneratedBy.Assigned();
Map(x => x.Description).Column("DESCRIPTION");
Map(x => x.OrderBy).Column("ORDER_BY");
DiscriminateSubClassesOnColumn("TYPE_CODE", "INVALID")
.SqlType("VARCHAR2");
}
}
And then there are a bunch of sub-classes that differ only in their
discriminator values.
Another mapping might reference this as:
...
References<FacilityType>(x =>
x.Type).Column("FACIL_TYPE_CODE").ReadOnly();
...
Now, this is all well and good, and everything works, since that reference
knows the class, and therefore the discriminator value for the query,
except...I only just hit the case where CODE_CODE is non-unique between two
objects of different types (both subtypes of Code) in the same session.
Oops.
CODE_CODE and TYPE_CODE are unique together, so the right thing ought to be
to use them as a composite key. But then my References in the other class
maps become impossible, because those tables only have a single column
foreign key (obviously no FK constraint defined on table).
Short of adding a surrogate key on the code table, whatever shall I do?
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.