楷模:
public class User
{
[Key]
public int UserId { get; set; }
public string UserName { get; set; }
}
public class Resource
{
[Key]
public int ResourceId { get; set; }
public string ResourceName { get; set; }
public string ResourceDescription { get; set; }
}
public class UserResource
{
[Key, Column(Order=0)]
public int UserId { get; set; }
[Key, Column(Order=1)]
public int ResourceId { get; set; }
public int ResourceQuantity { get; set; }
}
对于给定的“UserId”,我想从资源模型中选择“ResourceName”,从 UserResource 模型中选择“ResourceQuantity”。另外,一旦选择,我是否需要一个全新的模型来只携带这两个指定的列?
另请注意,UserResource 模型有一个复合键,所以我对如何进行连接感到困惑......这是对的吗?
var userResources =
from r in imDB.Resources
join ur in imDB.UserResources
on r.ResourceId equals ur.ResourceId
select new { r.ResourceName, ur.ResourceQuantity };