[英]Get all parents that have children using a c# lambda expression
-------PLEASE DISREGARD THIS POST---------- -------请忽略此职位----------
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? 在以下情况下,我将如何编写lambda查询?
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! 谢谢!
var categories = db.Categories.Where(category => category.Barcodes.Any())
或可能
var categories = db.Categories.Where(category => category.Barcode != null)
var catsWithBarCode = Categories.Where(c => c.Barcode != null);
From the description the relation seems to be: Category {1}---{0,1} Barcode 根据描述,该关系似乎是:类别{1} --- {0,1}条码
If the size of Categories is extremely large (it is always larger than Barcodes) the alternative will be more performant. 如果类别的大小非常大(它总是大于条形码),则替代方法的性能会更高。
Barcodes.Select(c => c.Category);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.