我正在尝试在 linq 中复制以下 SQL 查询:
Select
l.*,
ISNULL( i.InterestPercentage,0)
as InterestPercentage
FROM properties l
LEFT JOIN interest i on i.ListingKey = l.ListingKey
Where i.userId = {0}
目前我真的没什么可做的:
var results = from l in context.properties
join s in context.interest on l.ListingKey equals s.ListingKey
where s.userId == "";
这会返回一个完全连接,但我想返回带有单个附加值的属性,即InterestPercentage
. 我想我可能需要创建一个新对象,它是所有属性列以及一个额外的 InterestPercentage 属性。然后添加select new MyObject { tons of property setters }
.
此外,虽然我试图通过 Odata 公开这一点,但这样做会失去可查询的能力吗?