我需要将以下SQL语句转换为LINQ。我基本上是从数据库的视图转移到一个LINQ,我正在努力获得NOT IN和内部选择工作
SELECT DISTINCT *
FROM TFund F3,TFundMapping FM
WHERE F3.ID NOT IN
(SELECT ParentFundID
FROM TFundMapping)
AND FM.ChildFundID = F3.ID
作为一些背景知识,对于我的其他LINQ查询,我使用以下样式
public TxxxType[] GetxxxType()
{
var query = from item in _context.TxxxType
orderby item.ID
select item;
return _context.SelectPOCOsWCF(query);
}
我似乎无法使语法正确并符合上述风格 - 任何帮助都会受到赞赏,因为我在这个上撞砖墙
非常感谢
答案 0 :(得分:0)
此工具可帮助您实现目标
答案 1 :(得分:0)
你可以尝试这个,但未经测试:
var result = ( from record in _context.TFund
join fundMappingRecord in _context.TFundMapping
on record.ID equals fundMappingRecord.ChildFundID
where ( from subResult in _context.TFundMapping
select subResult.ParentFundID
).Contains( record.ID ) == false
select new
{
record,
fundMappingRecord
} ).Distinct( );
您仍然会遇到问题,因为您无法将匿名类型传递给其他方法。