我有这个 sql 表达式,我想使用实体框架或 linq 将其转换为代码语法
select [Key],name from products where [Key] not in (select distinct parent from products where parent is not null)
我有这个 sql 表达式,我想使用实体框架或 linq 将其转换为代码语法
select [Key],name from products where [Key] not in (select distinct parent from products where parent is not null)
我认为这会奏效。
var parents = products.Where(p => p.parent != null).Distinct();
var products = products.Where(p => !parents.Contains(p.Key))
.Select(p => new { p.Key, p.Name });
试试这个,可能对你有帮助
var p = products.Where(p => p.parent != null).select(p=>p.parent).Distinct();
var pro = products.Where(p => !p.Contains(p.Key))
.Select(p => new { ProKey = p.Key, ProName.Name });
可能它会起作用,但你仍然有问题让我知道......