我盯着 Linq,不知道如何处理这个查询。
我有一个 UserProfile 表。每个 UserProfile 可以有许多图像(UserImages 表)
我的模型(简化):
public class UserProfile
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Image> UsrImages { get; set; }
}
[Table("ImagesLocation")]
public class UserImages
{ //This is just an Id (and I don't even need it) It is not, from
public int Id { get; set; } what I can see, the UserProfile Id foreign key
public string ImgPath { get; set; }
public bool? ImgDefault { get; set; }
}
public class UserProfileDBContext : DbContext
{
public DbSet<UserProfile> UserProfiles { get; set; }
public DbSet<UserImages> userImages { get; set; }
}
我想要一个类似于以下内容的 linq 查询:
select * from dbo.imgLocation where userProfile_id = 1 (or any user id)
这将为特定用户带来一个包含所有“图像”(或图像数据/路径)的列表。我看到 EF 自动在 UserImages 表上创建了一个名为 userProfile_id 的列,但我无法使用 linq 查询它,因为它不存在!
我一直在谷歌上搜索它,但我什么也找不到(添加我尝试过的东西没有意义!..最终,我可以改变我的模型来完成这项工作。我的主要问题是我找不到钥匙/与我的 UserImages 模型上的 UserProfile 相关的外键
关于如何做到这一点的任何提示?谢谢!... PnP