[英]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.