我有桌子:
Items{ItemId, Title, CreatedBy, CreatedOnDate}
Likes{ItemId, UserId, CreatedOnDate}
在 ef 我有这两个模型:
[Table("Likes")]
public class Like
{
[Key, Column(Order = 1)]
public int ItemId { get; set; }
[Key, Column(Order = 2)]
public Guid UserId{ get; set; }
public DateTime CreatedOnDate { get; set; }
public virtual Item Item { get; set; }
public virtual User User { get; set; }
}
[Table("Items")]
public class Item
{
[Key]
public int ItemId { get; set; }
public virtual ICollection<Like> Likes { get; set; }
}
现在我有一个问题来获取用户喜欢的项目列表。我尝试了以下方法:
model = (from l in con.Likes
select new Item
{
UserId = l.Item.UserId,
Title = l.Item.Title,
Likes = l.Item.Likes,
User = l.Items.User,
CreatedOnDate = l.Ticket.CreatedOnDate,
ItemId = l.Ticket.ItemId
}).ToList();
我试过有和没有ToList()
. 我在这里做错了什么?