I have two entities that use the same class to represent a name:
Participant
class Participant
{
public PersonName Name { get; set; }
}
Judge
class Judge
{
public PersonName Name { get; set; }
}
PersonName
class PersonName
{
public string First { get; set; }
public string Last { get; set; }
public string Full { get; set; }
}
In the table for Participant
, the Last
value is a required (non-null) column. In the table for Judge
, only the Full
value is used (and optional). My problem is that EF is applying the IsRequired()
from my Participant mapping to the Judge
instance of PersonName
and thus failing when only the Full
value is supplied for a Judge
Entity.
Participant Mapping
Property(t => t.Name.Last)
开发者_如何学编程.IsRequired();
Judge Mapping
Property(t => t.Name.Full)
.HasMaxLength(100);
Entity Validation Error
The Judge.Name.Last field is required.
Is there a way to avoid this mapping collision other than creating separate PersonName
-like classes for each mapping situation?
Why to avoid separate class if your Judge
use only part of PersonName
values? Judge's Name is a different class.
Storage dependent part of complex type mapping is shared among entities using that type.
精彩评论