我有一个播放器类对象,其中包含一个图像作为其中一个属性。我正在尝试左边加入设备类,左边加入社交课程。我想要检索所有玩家,如果玩家有设备或社交属性,则相应地设置,如果设备或社交为空,则保留为空但仍显示玩家。
我目前正在获取“图像数据类型无法选择为DISTINCT,因为它无法比较。”错误。我正在尝试的查询:
var player = (from p in db.Players
join e in db.Equipment on p.PlayerId equals e.PlayerId
into playerequipment
from d in playerequipment.DefaultIfEmpty()
join so in db.Social on p.PlayerId equals so.PlayerId
into playersocial
from de in playersocial.DefaultIfEmpty()
where p.PlayerId == PlayerId
group new { p, d, de } by new
{
Player = p
} into x
select new
{
Player = x
});
由于
答案 0 :(得分:1)
尝试使用导航属性:
var players = db.Players.Where(player=> player.Equipment != null && player.Social != null).ToList();
如果您的导航属性以这种方式命名,则不知道......检查您的模型。
如果您想要检索它们,无论是否存在社交或设备:
var players = db.Players.Include("Social").Include("Equipment").ToList();