Created
June 20, 2026 03:39
-
-
Save c10r/4810fcd1aa00928c248ab9b8c7924a3f to your computer and use it in GitHub Desktop.
Linq example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public sealed class AppDbContext : DbContext | |
| { | |
| public DbSet<Customer> Customers => Set<Customer>(); | |
| public DbSet<Order> Orders => Set<Order>(); | |
| protected override void OnConfiguring(DbContextOptionsBuilder options) | |
| { | |
| options.UseTurso("libsql://my-db.turso.io", new TursoOptions | |
| { | |
| AuthToken = "<token>" | |
| }); | |
| } | |
| } | |
| public sealed class Customer | |
| { | |
| public long Id { get; set; } | |
| public string Name { get; set; } = ""; | |
| public string Email { get; set; } = ""; | |
| public bool IsActive { get; set; } | |
| public List<Order> Orders { get; set; } = []; | |
| } | |
| public sealed class Order | |
| { | |
| public long Id { get; set; } | |
| public long CustomerId { get; set; } | |
| public Customer Customer { get; set; } = null!; | |
| public decimal Total { get; set; } | |
| public DateTime CreatedAt { get; set; } | |
| } | |
| await using var db = new AppDbContext(); | |
| var activeCustomers = await db.Customers | |
| .Where(c => c.IsActive) | |
| .OrderBy(c => c.Name) | |
| .Take(50) | |
| .ToListAsync(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment