2012-12-24 13 views
-1

我创建了两个类。实体类型'AdminServiceCenter'和'ManagerServiceCenter'不能共享表'SrvCenters'

[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 
} 

[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 
} 

当我尝试叫ManagerServiceCenter。我有例外

的实体类型“AdminServiceCenter”和“ManagerServiceCenter”不能共享表“SrvCenters”,因为他们不是在同一类型层次或没有有效的一对一的外键关系与对应的主键它们之间。

为什么这个类的工作:)

/// <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; } 
} 

回答

2

,如果你想两个实体之间共享表必须使用TPH inheritancetable splitting

+0

但我不使用传统。 – Greg

+0

什么遗产?简单地将多个实体映射到同一个表具有自己的规则。你不能去任意的班级,让他们分享桌子。 –