[英]Get all parents that have children using a c# lambda expression
-------請忽略此職位----------
我先在文本編輯器中編寫帖子,然后再將其放在此處,然后完全粘貼錯誤的文本塊。
我好累,不應該操作重型機械或鍵盤。
我會在下面將答案標記為正確,因為它的確是正確的。
------免責聲明------------
在以下情況下,我將如何編寫lambda查詢?
All Barcodes have a Category, but not all Categories have a Barcode.
Select all Categories that have a Barcode.
尋找類似的東西:
var categories = db.Categories.Where(...)
這個問題可能已經有了答案,但是我顯然缺少尋找它的搜索詞。
謝謝!
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);
根據描述,該關系似乎是:類別{1} --- {0,1}條碼
如果類別的大小非常大(它總是大於條形碼),則替代方法的性能會更高。
Barcodes.Select(c => c.Category);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.