![](/img/trans.png)
[英]How do I overwrite a foreign key column in Entity Framework Core 6?
[英]How do I specify which column is the Foreign key and which column is the Primary Key on a one-to-many relationship. Using Entity Framework Core
我有兩張這樣的桌子
public class Shepherd
{
public long Id { get; set; }
public string Name { get; set; }
public string UserId{ get; set; }
}
public class Goat
{
public long Id { get; set; }
public string Hairyness { get; set; }
public string CreatedBy { get; set; }
}
我知道如何使用ID創建一對多關系,但我需要使用UserId和“ CreatedBy ”列創建從 Shepherd 到許多山羊的一對多關系。 我希望這是有道理的。 非常感謝。
我找到了自己的解決方案。 使用 Linq。
var goatPoo = from Goats in _context.Goats
join Shepherd in _context.Shepherds
on Goats.CreatedBy equals Shepherd.UserId
where Shepherd.UserId == 77
select new {
Shepherd.Id,
Shepherd.Firstname,
Shepherd.Lastname,
Goats.Hairyness
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.