多对一关系上的实体框架导航属性

时间:2014-02-14 10:53:30

标签: c# sql entity-framework

被修改

我正试图在我已经拥有的两张桌子上建立一对一的关系,但我无法使其成功。我尝试了不同的选项,但我最终只检索了一个表的记录。

以下是我的表结构:

客户

[Table("Customer")]
public class CustomerList
{
    [Key]
    public int CustomerID { get; set; }
    public int Number { get; set; }
    public string Surname { get; set; }
    public string Forename { get; set; }
    public DateTime? DateOfBirth { get; set; }

    public int? MembershipTypeID { get; set; }
    public MembershipTypeList MembershipType { get; set; }
    public string Name;

    public string EmailAddress { get; set; }
}

MembershipType

[Table("MembershipType")]
public class MembershipTypeList
{
    [Key]
    public int? MembershipTypeID { get; set; }
    public string Name { get; set; }

    //public virtual CustomerList Customer { get; set; }
}

结果

CustomerID 56
Number 52
Surname Antonelli
Forename Renny
DateOfBirth 1945-02-19
MembershipTypeID 1
EmailAddress Mr@test.com
Name NULL

预期

CustomerID 56 
Number 52 
Surname Antonelli 
Forename Renny 
DateOfBirth 1945-02-19 
MembershipTypeID 1 
EmailAddress Mr@test.com 
Name Blue ---> from membershiptype table

0 个答案:

没有答案