ရိုးရိုးလေး ရှင်းပြမယ်
LINQ: Querying Collections ကို ရိုးရိုးလေးနားလည်မယ်
LINQ သည် collection နှင့် အခြား data source များကို strongly typed query ရေးနိုင်စေသည်။ Where က filter လုပ်ပြီး Select က shape ပြောင်းပေးသည်။ Query တစ်ခုကို ToList() မခေါ်မချင်း deferred execution ဖြစ်နိုင်သည်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Query ကိုloop အတွင်းအကြိမ်ကြိမ်enumerate လုပ်ခြင်း သို့database LINQ အားlocal LINQ လိုယူဆခြင်းကperformance ပြဿနာဖြစ်စေပါတယ်။
ဖြစ်လေ့ရှိတဲ့အမှား
Happy path တစ်ခု run အောင်ရုံဖြင့် code မှန်ကန်၊ maintainable နဲ့production-ready ဖြစ်ပြီဟုယူဆခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
LINQ ကstrongly typed sequences ကိုfilter, transform, order, group နဲ့aggregate လုပ်စေပါတယ်။ Query definition နဲ့execution ကိုခွဲသိပြီး deferred execution, multiple enumeration, `IEnumerable<T>` နဲ့remote `IQueryable<T>` translation ကွာခြားချက်ကိုစစ်ပါ။
- Task / collection
- .NET API + pipeline
- Typed result / failure
LINQ: Querying Collections ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
var scores = new[] { 68, 42, 91, 77, 55 };
var passed = scores
.Where(score => score >= 60)
.OrderByDescending(score => score)
.Select(score => $"Score: {score}")
.ToList();
passed.ForEach(Console.WriteLine);
Console.WriteLine($"Average: {scores.Average():0.0}");LINQ ကstrongly typed sequences ကိုfilter, transform, order, group နဲ့aggregate လုပ်စေပါတယ်။ Query definition နဲ့execution ကိုခွဲသိပြီး deferred execution, multiple enumeration, `IEnumerable<T>` နဲ့remote `IQueryable<T>` translation ကွာခြားချက်ကိုစစ်ပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Task / collection
var scores = new[] { 68, 42, 91, 77, 55 };LINQ သည် collection နှင့် အခြား data source များကို strongly typed query ရေးနိုင်စေသည်။ Where က filter လုပ်ပြီး Select က shape ပြောင်းပေးသည်။ Query တစ်ခုကို ToList() မခေါ်မချင်း deferred execution ဖြစ်နိုင်သည်။
- .NET API + pipeline
.Select(score => $"Score: {score}")LINQ ကstrongly typed sequences ကိုfilter, transform, order, group နဲ့aggregate လုပ်စေပါတယ်။ Query definition နဲ့execution ကိုခွဲသိပြီး deferred execution, multiple enumeration, `IEnumerable<T>` နဲ့remote `IQueryable<T>` translation ကွာခြားချက်ကိုစစ်ပါ။
- Typed result / failure
Console.WriteLine($"Average: {scores.Average():0.0}");Products ကိုWhere/OrderBy/Select ဖြင့်DTO shape ပြောင်းပြီး source ပြောင်းမီ/ပြောင်းပြီးနောက် enumerate ကွာခြားချက်ကိုစမ်းပါ။
- Task / collection
- .NET API + pipeline
- Typed result / failure
Success
LINQ: Querying Collections ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
Failure
Query ကိုloop အတွင်းအကြိမ်ကြိမ်enumerate လုပ်ခြင်း သို့database LINQ အားlocal LINQ လိုယူဆခြင်းကperformance ပြဿနာဖြစ်စေပါတယ်။
ရိုးရိုးလေး ရှင်းပြမယ်
LINQ သည် collection နှင့် အခြား data source များကို strongly typed query ရေးနိုင်စေသည်။ Where က filter လုပ်ပြီး Select က shape ပြောင်းပေးသည်။ Query တစ်ခုကို ToList() မခေါ်မချင်း deferred execution ဖြစ်နိုင်သည်။
var scores = new[] { 68, 42, 91, 77, 55 };
var passed = scores
.Where(score => score >= 60)
.OrderByDescending(score => score)
.Select(score => $"Score: {score}")
.ToList();
passed.ForEach(Console.WriteLine);
Console.WriteLine($"Average: {scores.Average():0.0}");Score: 91
Score: 77
Score: 68
Average: 66.6လက်တွေ့စမ်းကြည့်ရန်
Products collection ကို category ဖြင့် filter လုပ်ပြီး price အနိမ့်မှအမြင့် sort လုပ်ကာ name နှင့် price သာရွေးပါ။
Language Integrated Query (LINQ) — Microsoft Learn
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Products ကိုWhere/OrderBy/Select ဖြင့်DTO shape ပြောင်းပြီး source ပြောင်းမီ/ပြောင်းပြီးနောက် enumerate ကွာခြားချက်ကိုစမ်းပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Products ကိုWhere/OrderBy/Select ဖြင့်DTO shape ပြောင်းပြီး source ပြောင်းမီ/ပြောင်းပြီးနောက် enumerate ကွာခြားချက်ကိုစမ်းပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
var scores = new[] { 68, 42, 91, 77, 55 };
var passed = scores
.Where(score => score >= 60)
.OrderByDescending(score => score)
.Select(score => $"Score: {score}")
.ToList();
passed.ForEach(Console.WriteLine);
Console.WriteLine($"Average: {scores.Average():0.0}");ရလဒ်: LINQ: Querying Collections ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Products ကိုWhere/OrderBy/Select ဖြင့်DTO shape ပြောင်းပြီး source ပြောင်းမီ/ပြောင်းပြီးနောက် enumerate ကွာခြားချက်ကိုစမ်းပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Task / collection → .NET API + pipeline → Typed result / failure
- LINQ ကstrongly typed sequences ကိုfilter, transform, order, group နဲ့aggregate လုပ်စေပါတယ်။ Query definition နဲ့execution ကိုခွဲသိပြီး deferred execution, multiple enumeration, `IEnumerable<T>` နဲ့remote `IQueryable<T>` translation ကွာခြားချက်ကိုစစ်ပါ။
- Query ကိုloop အတွင်းအကြိမ်ကြိမ်enumerate လုပ်ခြင်း သို့database LINQ အားlocal LINQ လိုယူဆခြင်းကperformance ပြဿနာဖြစ်စေပါတယ်။
- Products ကိုWhere/OrderBy/Select ဖြင့်DTO shape ပြောင်းပြီး source ပြောင်းမီ/ပြောင်းပြီးနောက် enumerate ကွာခြားချက်ကိုစမ်းပါ။
Language Integrated Query (LINQ) — Microsoft Learn