-1

I was created two class.

[Table("SrvCenters")]
public class ManagerServiceCenter
{
    #region Public Properties

    /// <summary>
    /// Gets or sets the srv center id.
    /// </summary>
    [Key]
    public int SrvCenterId { get; set; }

    /// <summary>
    /// Gets or sets the branch id.
    /// </summary>
    public int BranchId { get; set; }

    /// <summary>
    /// Gets or sets the branch.
    /// </summary>
    public virtual Branch Branch { get; set; }

    /// <summary>
    /// Gets or sets the location id.
    /// </summary>
    public int LocationId { get; set; }

    /// <summary>
    /// Gets or sets the location.
    /// </summary>
    public virtual Location Location { get; set; }

    /// <summary>
    /// Gets or sets the description.
    /// </summary>
    public string Description { get; set; }

    /// <summary>
    /// Gets or sets the domain name.
    /// </summary>
    public string DomainName { get; set; }

    /// <summary>
    /// Gets or sets the active.
    /// </summary>
    public int Active { get; set; }

    #endregion
}

and

[Table("SrvCenters")]
public class AdminServiceCenter
{
    #region Public Properties

    /// <summary>
    /// Gets or sets the srv center id.
    /// </summary>
    [Key]
    public int SrvCenterId { get; set; }

    /// <summary>
    /// Gets or sets the active.
    /// </summary>
    public int Active { get; set; }

    /// <summary>
    /// Gets or sets the begin break.
    /// </summary>
    public TimeSpan BeginBreak { get; set; }

    /// <summary>
    /// Gets or sets the begin day.
    /// </summary>
    public TimeSpan BeginDay { get; set; }

    /// <summary>
    /// Gets or sets the branch id.
    /// </summary>
    public int BranchId { get; set; }

    /// <summary>
    /// Gets or sets the branch.
    /// </summary>
    public virtual Branch Branch { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether check time table.
    /// </summary>
    public int CheckTimeTable { get; set; }

    /// <summary>
    /// Gets or sets the create time.
    /// </summary>
    public DateTime? CreateTime { get; set; }

    /// <summary>
    /// Gets or sets the create user.
    /// </summary>
    public string CreateUser { get; set; }

    /// <summary>
    /// Gets or sets the cust priority id.
    /// </summary>
    public int CustPriorityId { get; set; }

    /// <summary>
    /// Gets or sets the customer bind id.
    /// </summary>
    public int CustomerBindId { get; set; }

    /// <summary>
    /// Gets or sets the delete count.
    /// </summary>
    public int DeleteCount { get; set; }

    /// <summary>
    /// Gets or sets the delete time.
    /// </summary>
    public int DeleteTime { get; set; }

    /// <summary>
    /// Gets or sets the description.
    /// </summary>
    public string Description { get; set; }

    /// <summary>
    /// Gets or sets the domain name.
    /// </summary>
    public string DomainName { get; set; }

    /// <summary>
    /// Gets or sets the end break.
    /// </summary>
    public TimeSpan EndBreak { get; set; }

    /// <summary>
    /// Gets or sets the end day.
    /// </summary>
    public TimeSpan EndDay { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether estimate wait time.
    /// </summary>
    public int EstimateWaitTime { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether have break.
    /// </summary>
    public int HaveBreak { get; set; }

    /// <summary>
    /// Gets or sets the hold order.
    /// </summary>
    public int HoldOrder { get; set; }

    /// <summary>
    /// Gets or sets the location id.
    /// </summary>
    public int LocationId { get; set; }

    /// <summary>
    /// Gets or sets the notif interval.
    /// </summary>
    public int NotifInterval { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether notification.
    /// </summary>
    public int Notification { get; set; }

    /// <summary>
    /// Gets or sets the priority direct id.
    /// </summary>
    public int PriorityDirectId { get; set; }

    /// <summary>
    /// Gets or sets the serv priority id.
    /// </summary>
    public int ServPriorityId { get; set; }

    /// <summary>
    /// Gets or sets the service bind id.
    /// </summary>
    public int ServiceBindId { get; set; }

    /// <summary>
    /// Gets or sets the srv center guid.
    /// </summary>
    public Guid SrvCenterGuid { get; set; }

    /// <summary>
    /// Gets or sets the sequence id.
    /// </summary>
    public int SequenceId { get; set; }

    /// <summary>
    /// Gets or sets the sequence.
    /// </summary>
    public virtual Sequence Sequence { get; set; }

    #endregion
}

When try I called ManagerServiceCenter. I got exception

The entity types 'AdminServiceCenter' and 'ManagerServiceCenter' cannot share table 'SrvCenters' because they are not in the same type hierarchy or do not have a valid one to one foreign key relationship with matching primary keys between them.

Ok

Why this class working :)

/// <summary>
/// The workplace setting.
/// </summary>
[Table("SrvCenters")]
public class WorkplaceSetting
{
    /// <summary>
    /// Gets or sets the srv center id.
    /// </summary>
    [Key]
    public int SrvCenterId { get; set; }

    /// <summary>
    /// Gets or sets the net ident type id.
    /// </summary>
    public int NetIdentTypeId { get; set; }

    /// <summary>
    /// Gets or sets the help net ident type.
    /// </summary>
    [ForeignKey("NetIdentTypeId")]
    public virtual HelpNetIdentType HelpNetIdentType { get; set; }

    /// <summary>
    /// Gets or sets the w p_ auto start exec.
    /// </summary>
    public int WP_AutoStartExec { get; set; }

    /// <summary>
    /// Gets or sets the w p_ button mask.
    /// </summary>
    public int WP_ButtonMask { get; set; }

    /// <summary>
    /// Gets or sets the w p_ show info.
    /// </summary>
    public int WP_ShowInfo { get; set; }

    /// <summary>
    /// Gets or sets the w p_ show message.
    /// </summary>
    public int WP_ShowMessage { get; set; }

    /// <summary>
    /// Gets or sets the w p_ time between msg.
    /// </summary>
    public int WP_TimeBetweenMsg { get; set; }

    /// <summary>
    /// Gets or sets the w p_ time in idle.
    /// </summary>
    public int WP_TimeInIdle { get; set; }

    /// <summary>
    /// Gets or sets the w p_ time in resolve.
    /// </summary>
    public int WP_TimeInResolve { get; set; }

    /// <summary>
    /// Gets or sets the w p_ time show msg.
    /// </summary>
    public int WP_TimeShowMsg { get; set; }

    /// <summary>
    /// Gets or sets the description.
    /// </summary>
    public string Description { get; set; }

    /// <summary>
    /// Gets or sets the active.
    /// </summary>
    public int Active { get; set; }
}
Hryhorii
  • 1,083
  • 3
  • 17
  • 38

1 Answers1

2

You must use TPH inheritance or table splitting if you want to share table between two entities.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • What legacy? Simply mapping multiple entities to the same table has its own rules. You cannot take to arbitrary classes and let them share the table. – Ladislav Mrnka Dec 24 '12 at 13:16