Question

I have this sql expression and I want to convert it into a code syntax using entity framework or linq

select [Key],name from products where [Key] not in (select distinct parent from products where parent is not null)
Était-ce utile?

La solution

Try this one, may be it can help you

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 }); 

May be its will work, and still you having problem that let me know...

Autres conseils

I think this will work.

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 }); 
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top