2014-11-04 108 views
0

我正尝试使用modelBuilder在我的数据库中映射外键。我需要将Id发布到JobTESPM_EmployeeId而不是JOBTESPMId。我一直在使用这个指南,但我看不到这些示例与我的设置相同。 http://msdn.microsoft.com/en-in/data/jj591620.aspx#IndependentAssociation如何使用Fluent API映射外键

public class Job 
{ 
    [Key] 
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.None)] 
    public Int64? JobId { get; set; } 
    public int? JobNumber { get; set; } 
    public string JobName { get; set; } 
    public int? JobTypeId { get; set; } 

    public int? CustomerEmployeePMId { get; set; } 
    public virtual CustomerEmployee CustomerEmployeePM { get; set; } 

    public int? CustomerEmployeeAdminId { get; set; } 
    public virtual CustomerEmployee CustomerEmployeeAdmin { get; set; } 

    public int? CustomerEmployeeAccountantId { get; set; } 
    public virtual CustomerEmployee CustomerEmployeeAccountant { get; set; } 

    public int? CustomerEmployeeSuperintendentId { get; set; } 
    public virtual CustomerEmployee CustomerEmployeeSuperintendent { get; set; } 

    public int? JobTESPMId { get; set; } 
    public virtual Employee JobTESPM { get; set; } 

    public int? JobTESSuperintendentId { get; set; } 
    public virtual Employee JobTESSuperintendent { get; set; } 
} 

public class Employee 
{ 
    public int EmployeeId { get; set; } 
    public string AccountName { get; set; } 
    public string EmployeeFirstName { get; set; } 
    public string EmployeeLastName { get; set; } 
    public string EmployeeTitle { get; set; } 
    public Int64? EmployeeCellPhone { get; set; } 
    public Int64? EmployeeOfficePhone { get; set; } 
    public string EmployeeEmail { get; set; } 
    public int? CompanyEmployeeId { get; set; } 
    public bool? EmployeeHidden { get; set; } 
    public bool? EmployeeIsSuper { get; set; } 
    public bool? EmployeeIsPM { get; set; } 
    public string EmployeeAltEmail { get; set; } 
} 

pic

+0

你的意思是你要链接到JobTESPM_EmployeeId数据库列名为JOBTESPMId领域? – Kelly 2014-11-04 18:29:44

+0

好吧,我有点困惑这种关系如何工作,但是,我相信这是我需要的。 – texas697 2014-11-04 18:35:26

回答

1

有关添加一对夫妇的属性是什么?

[Column("JobTESPM_EmployeeID")] 
public int? JobTESPMId { get; set; } 
[ForeignKey("JobTESPMId")] 
public virtual Employee JobTESPM { get; set; } 
相关问题