链接EF CORE中的第三个模型

时间:2017-07-06 08:49:15

标签: entity-framework asp.net-core ef-code-first

这是我目前的EF核心设置。

电话型号

[ForeignKey("TelNoTypeID")]
public int? TelNoTypeID { get; set; }
public DropDown TelNoType { get; set; }

人物模型

public ICollection<Telephone> TelephoneIDs { get; set; }

我也尝试过使用

public virtual ICollection<Telephone> TelephoneIDs { get; set; }

DropDown模型

public int DropDownID { get; set; }
public string DisplayText { get; set; }

人员控制器

public async Task<IActionResult> Details(int? id)
{
    var person = await _context.Persons
        .Include(p => p.Gender)
        .Include(p => p.Title)
        .Include(p => p.AddressIDs)
        .Include(p => p.TelephoneIDs)
        .SingleOrDefaultAsync(m => m.PersonID == id);

因此,针对Person模型存储了一组电话号码。

从数据库返回并在屏幕上显示字段

中的数值
Telephones.TelNoTypeID

与我所拥有的等价的SQL是

select Telephones.TelNoTypeID from Person
inner join Telephones on Telephones.PersonID = Person.PersonID

我需要显示链接的文本值,而不是存储在

DropDown.displaytext 

我需要的等价SQL是

select DropDown.displaytext from Person
inner join Telephones on Telephones.PersonID = Person.PersonID
inner join DropDown on DropDown.DropDownID = Telephones.TelNoTypeID

我尝试过使用

.ThenInclude(p => p.<something>)

但Dot符号只是指通用集合属性/方法,而不是回到我的人,下拉列表或电话模型

我已将Person模型直接链接到Dropdown模型,使用并显示dropdown.displaytext

人物模型

[ForeignKey("GenderID")]
public int? GenderID { get; set; }
public virtual DropDown Gender { get; set; }

但是尽管将相同的代码放入电话,它仍无法正常工作

如何将第三个模型(DropDown)链接到第二个模型(电话)?

由于

1 个答案:

答案 0 :(得分:-2)

我试图链接到DropDown模型,结果我需要链接到属性,所以

cart

我不明白为什么,我推测它是因为三个模型和ThenInclude之间已经存在链接指向我试图链接的确切属性/到。

相关问题