I have a Sales Order Program that allows each customer to have their own Part Number for one of our Stock Items. The Customer Part Numbers are stored in a separate table. I need to make this as low impact on the User/UI as possible. As a working model I have come up with a related demo using Person for the Order Table and a Table called NickNames that should represent the Customer Part Number Table.
public class Person
{
private string _sobriquet;
public Person()
{
NickName = new NickName(Id);
}
[Key]
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int NickNameId { get; set; }
[ForeignKey("NickNameId")]
public virtual NickName NickName { get; set; }
public string Sobriquet
{
get { return _sobriquet; }
set
{
_sobriquet = value;
NickName.PersonId = Id;
NickName.Sobriquet = _sobriquet;
}
}
}
public class NickName
{
public NickName(int personId)
{
PersonId = personId;
}
protected NickName()
{
}
[Key]
public int PersonId { get; set; }
public string Sobriquet { get; set; }
}
This does what I wanted... by Changing the Sobriquet property on the Person table the NickName Table is updated, but I am sure there is a better or cleaner way.