crowhill crowhill -4 years ago 141
C# Question

Get all parents that have children using a c# lambda expression


I write my posts in a text editor before I put them here and I pasted in the wrong block of text entirely.

I'm so tired I shouldn't be operating heavy machinery or keyboards.

I will mark the answer below as correct, because it certainly is.

------END DISCLAIMER------------

How would I write a lambda query for the following scenario?

All Barcodes have a Category, but not all Categories have a Barcode.

Select all Categories that have a Barcode.

Looking for something along the lines of:

var categories = db.Categories.Where(...)

This question probably already has an answer, but I apparently lack the search terms to find it.

Thank you!

Answer Source
var categories = db.Categories.Where(category => category.Barcodes.Any())

or possibly

var categories = db.Categories.Where(category => category.Barcode != null)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download