Sr. Content Developer at Microsoft, working remotely in PA, TechBash conference organizer, former Microsoft MVP, Husband, Dad and Geek.
153047 stories
·
33 followers

Day 20: AI as Debugger

1 Share

You know the drill. Something’s broken. You’re not sure where. You add a console.log. Then another. Then twelve more. You run it again. The bug doesn’t appear. You add more logs. Now it appears but the logs don’t help. You start guessing.

This is debugging by wandering. It works eventually, but it’s slow and frustrating.

Here’s what I’ve learned: AI is annoyingly good at debugging. Not because it’s smarter, but because it’s systematic. You describe the symptoms, AI lists the likely causes in order of probability, and you work through them methodically.

While you’re guessing, AI is pattern matching against every bug it’s ever seen.

Why AI Is Good at Debugging

Debugging is pattern matching. You have a symptom. You need to find the cause. The space of possible causes is large.

AI has seen millions of bugs. It recognizes patterns: “silently fails sometimes” often means race condition, async issue, or swallowed error. “Works locally but not in production” often means environment variables, database differences, or timing issues.

When you describe a bug, AI immediately narrows to the most likely categories. Then it helps you test each one systematically.

The Debugging Prompt

Here’s the prompt that starts most debugging sessions:

I have a bug. Help me find it.

Symptom: [describe what's happening]
Expected: [describe what should happen]
Frequency: [always / sometimes / rarely]
Environment: [local / staging / production]

Relevant code:
[paste the code you think is involved]

Recent changes:
[paste recent commits if relevant]

What I've tried:
[what have you already ruled out?]

Help me:
1. List the top 5 most likely causes
2. For each cause, how would I confirm or rule it out?
3. What logging would help narrow it down?

A Real Debugging Session

Here’s how the card transfer bug went:

Me:

I have a bug. Help me find it.

Symptom: Card transfers sometimes fail silently. The API returns
success, but the card stays with the original owner.

Expected: Card ownership should transfer to the new owner.

Frequency: Sometimes. Maybe 1 in 100 transfers.

Environment: Production only. Can't reproduce locally.

Relevant code:
[pasted the transferCard function]

What I've tried:
- Added logging to the function
- Checked for database errors
- Verified the API is being called correctly

AI:

Top 5 most likely causes for intermittent silent failures:

1. Race condition in concurrent transfers
   The ownership check and update aren't atomic. Two concurrent
   transfers could both pass the ownership check before either writes.

   Confirm: Add logging with timestamps before check and after write.
   Look for overlapping timestamps in production logs.

2. Database transaction isolation
   Default isolation level might allow dirty reads where the ownership
   check sees stale data.

   Confirm: Check your database isolation level. Test with two
   simultaneous transfers of the same card.

3. Stale cache
   If you're caching card data, the check might use cached ownership
   while the write goes to the database.

   Confirm: Check for any caching layer. Try disabling cache and
   testing.

4. Optimistic locking failure without proper handling
   If using optimistic locking, version conflicts might be silently
   swallowed.

   Confirm: Search for where version conflicts are caught. Check if
   they're being logged.

5. Unhandled promise rejection
   An async operation might be failing without the error bubbling up.

   Confirm: Add try/catch around all async operations. Add
   .catch() to any promises.

The race condition hypothesis led me to add timestamp logging. Sure enough, I found cases where two transfers were within 50ms of each other. Both passed the check. Both tried to write. Only one succeeded. The other silently did nothing because the ownership had already changed.

The Hypothesis-Test Loop

Good debugging is scientific. Hypothesis, test, refine.

Based on our debugging so far:

Hypothesis: [what you now think the cause is]
Evidence: [what supports this hypothesis]
Against: [what doesn't fit this hypothesis]

Next test: [what would confirm or refute this]

Generate the specific code or query I should run to test this hypothesis.

This keeps the debugging focused. No more random changes hoping something works.

Log Analysis

When you have logs but can’t see the pattern:

Analyze these logs for the bug we're tracking.

Bug: [describe the symptom]

Logs from successful operation:
[paste logs]

Logs from failed operation:
[paste logs]

Compare them:
1. What's different between success and failure?
2. What's missing in the failure case?
3. What sequence of events leads to failure?
4. What timestamp patterns do you notice?

AI is good at spotting differences humans miss. Different order of operations. Missing log entries. Timing anomalies.

Stack Trace Analysis

When you have a stack trace but don’t understand it:

Explain this stack trace and help me find the root cause.

Error: [paste the error message]

Stack trace:
[paste the full stack trace]

For each frame:
1. What file and function?
2. What was it trying to do?
3. Is this library code or our code?

Then:
1. Where did the error actually originate?
2. What caused the error?
3. What's the fix?

The Rubber Duck With Context

Sometimes you just need to explain the problem:

I'm stuck on a bug. Let me explain it to you, and ask questions
that help me think through it.

The bug: [describe it]

The code: [paste it]

Ask me questions about:
1. What I've already tried
2. What I expect vs what happens
3. Any recent changes
4. Edge cases I might have missed

AI asking you questions often reveals assumptions you didn’t realize you were making.

Narrowing Down

When the bug could be anywhere:

Help me narrow down where this bug lives.

System overview: [describe the components involved]

The bug: [describe the symptom]

Help me create a binary search:
1. What's the midpoint? What can I test to determine if the bug
   is in the first half or second half of the flow?
2. Based on that test, what's the next midpoint?

Goal: narrow to a single component in as few tests as possible.

Common Bug Patterns

AI recognizes these patterns instantly:

“Works sometimes” → Race condition, caching, timing issue

“Works locally, fails in production” → Environment config, data volume, network latency

“Worked yesterday, broken today” → Recent commit, dependency update, data change

“First request works, subsequent fail” → State mutation, connection pool, memory leak

“Works for me, fails for users” → Permissions, data differences, browser/client differences

Tell AI which pattern matches your bug, and it knows where to look.

Adding Strategic Logging

When you need more visibility:

I need to add logging to debug this issue.

The bug: [describe it]
The code: [paste it]

Generate logging that will help me:
1. Trace the exact path execution takes
2. See the state at each decision point
3. Capture timing information
4. Include enough context to identify the specific request

Use our logging format: [describe your logging pattern]

Make the logging easy to add and remove.

The Fix Verification Prompt

Once you think you’ve found it:

I think I found the bug and have a fix.

The bug: [describe it]
The cause: [describe what was wrong]
The fix: [paste your fix]

Review this fix:
1. Does it actually address the root cause?
2. Could it introduce new bugs?
3. What tests should I add to prevent regression?
4. Are there other places with the same bug pattern?

Debugging AI-Generated Bugs

AI code has predictable bug patterns:

This is AI-generated code that has a bug.

The bug: [describe it]
The code: [paste it]

Common AI code bugs:
- Off-by-one errors in loops
- Missing null checks
- Incorrect async/await handling
- Wrong array methods (map vs forEach vs filter)
- Missing error handling
- Incorrect type coercion

Check for these patterns first.

Tomorrow

Debugging is reactive. You find bugs after they exist. But what about bugs in production where you can’t just add console.log?

Tomorrow I’ll cover production debugging: when it’s on fire and you need to find problems with only the observability you already have.


Try This Today

  1. Think of a bug you recently spent too long finding
  2. Write up the initial prompt as if you were starting fresh
  3. See what AI suggests

Notice how quickly AI narrows to likely categories. That systematic approach is what makes AI debugging faster than random guessing.

Next time you hit a bug, start with AI instead of ending with it.

Read the whole story
alvinashcraft
just a second ago
reply
Pennsylvania, USA
Share this story
Delete

AWS Weekly Roundup: Kiro CLI latest features, AWS European Sovereign Cloud, EC2 X8i instances, and more (January 19, 2026)

1 Share

At the end of 2025 I was happy to take a long break to enjoy the incredible summers that the southern hemisphere provides. I’m back and writing my first post in 2026 which also happens to be my last post for the AWS News Blog (more on this later).

The AWS community is starting the year strong with various AWS re:invent re:Caps being hosted around the globe, with some communities already hosting their AWS Community Day events, the AWS Community Day Tel Aviv 2026 was hosted last week.

Last week’s launches
Here are last week’s launches that caught my attention:

  • Kiro CLI latest features – Kiro CLI now has granular controls for web fetch URLs, keyboard shortcuts for your custom agents, enhanced diff views, and much more. With these enhancements, you can now use allowlists or blocklists to restrict which URLs the agent can access, ensure a frictionless experience when working with multiple specialized agents in a single session, to name a few.
  • AWS European Sovereign Cloud – Following an announcement in 2023 of plans to build a new, independent cloud infrastructure, last week we announced the general availability of the AWS European Sovereign Cloud to all customers. The cloud is ready to meet the most stringent sovereignty requirements of European customers with a comprehensive set of AWS services.
  • Amazon EC2 X8i instancesPreviously launched in preview at AWS re:Invent 2025, last week we announced the general availability of new memory-optimized Amazon Elastic Compute Cloud (Amazon EC2) X8i instances. These instances are powered by custom Intel Xeon 6 processors with a sustained all-core turbo frequency of 3.9 GHz, available only on AWS. These SAP certified instances deliver the highest performance and fastest memory bandwidth among comparable Intel processors in the cloud.

Additional updates
These projects, blog posts, and news articles also caught my attention:

  • 5 core features in Amazon Quick Suite – AWS VP Agentic AI Swami Sivasubramanian talks about how he uses Amazon Quick Suite for just about everything. In October 2025 we announced Amazon Quick Suite, a new agentic teammate that quickly answers your questions at work and turns insights into actions for you. Amazon Quick Suite has become one of my favorite productivity tools, helping me with my research on various topics in addition to providing me with multiple perspectives on a topic.
  • Deploy AI agents on Amazon Bedrock AgentCore using GitHub Actions – Last year we announced Amazon Bedrock AgentCore, a flexible service that helps you seamlessly create and manage AI agents across different frameworks and models, whether hosted on Amazon Bedrock or other environments. Learn how to use a GitHub Actions workflow to automate the deployment of AI agents on AgentCore Runtime. This approach delivers a scalable solution with enterprise-level security controls, providing complete continuous integration and delivery (CI/CD) automation.

Upcoming AWS events
Join us January 28 or 29 (depending on your time zone) for Best of AWS re:Invent, a free virtual event where we bring you the most impactful announcements and top sessions from AWS re:Invent. Jeff Barr, AWS VP and Chief Evangelist, will share his highlights during the opening session.

There is still time until January 21 to compete for $250,000 in prizes and AWS credits in the Global 10,000 AIdeas Competition (yes, the second letter is an I as in Idea, not an L as in like). No code required yet: simply submit your idea, and if you’re selected as a semifinalist, you’ll build your app using Kiro within AWS Free Tier limits. Beyond the cash prizes and potential featured placement at AWS re:Invent 2026, you’ll gain hands-on experience with next-generation AI tools and connect with innovators globally.

Earlier this month, the 2026 application for the Community Builders program launched. The application is open until January 21st, midnight PST so here’s your last chance to ensure that you don’t miss out.

If you’re interested in these opportunities, join the AWS Builder Center to learn with builders in the AWS community.

With that, I close one of my most meaningful chapters here at AWS. It’s been an absolute pleasure to write for you and I thank you for taking the time to read the work that my team and I pour our absolute hearts into. I’ve grown from the close collaborations with the launch teams and the feedback from all of you. The Sub-Sahara Africa (SSA) community has grown significantly, and I want to dedicate more time focused on this community, I’m still at AWS and I look forward to meeting at an event near you!

Check back next Monday for another Weekly Roundup!

Veliswa Boya

Read the whole story
alvinashcraft
7 hours ago
reply
Pennsylvania, USA
Share this story
Delete

#466 PSF Lands $1.5 million

1 Share
Topics covered in this episode:
Watch on YouTube

About the show

Sponsored by us! Support our work through:

Connect with the hosts

Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Monday at 11am PT. Older video versions available there too.

Finally, if you want an artisanal, hand-crafted digest of every week of the show notes in email form? Add your name and email to our friends of the show list, we'll never share it.

Brian #1: Better Django management commands with django-click and django-typer

Michael #2: PSF Lands a $1.5 million sponsorship from Anthropic

  • Anthropic is partnering with the Python Software Foundation in a landmark funding commitment to support both security initiatives and the PSF's core work.
  • The funds will enable new automated tools for proactively reviewing all packages uploaded to PyPI, moving beyond the current reactive-only review process.
  • The PSF plans to build a new dataset of known malware for capability analysis
  • The investment will sustain programs like the Developer in Residence initiative, community grants, and infrastructure like PyPI.

Brian #3: How uv got so fast

  • Andrew Nesbitt
  • It’s not just be cause “it’s written in Rust”.
  • Recent-ish standards, PEPs 518 (2016), 517 (2017), 621 (2020), and 658 (2022) made many uv design decisions possible
  • And uv drops many backwards compatible decisions kept by pip.
  • Dropping functionality speeds things up.
    • “Speed comes from elimination. Every code path you don’t have is a code path you don’t wait for.”
  • Some of what uv does could be implemented in pip. Some cannot.
  • Andrew discusses different speedups, why they could be done in Python also, or why they cannot.
  • I read this article out of interest. But it gives me lots of ideas for tools that could be written faster just with Python by making design and support decisions that eliminate whole workflows.

Michael #4: PyView Web Framework

Extras

Brian:

  • Upgrade Django, has a great discussion of how to upgrade version by version and why you might want to do that instead of just jumping ahead to the latest version. And also who might want to save time by leapfrogging
    • Also has all the versions and dates of release and end of support.
  • The Lean TDD book 1st draft is done.
    • Now available through both pythontest and LeanPub
      • I set it as 80% done because of future drafts planned.
    • I’m working through a few submitted suggestions. Not much feedback, so the 2nd pass might be fast and mostly my own modifications. It’s possible.
    • I’m re-reading it myself and already am disappointed with page 1 of the introduction. I gotta make it pop more. I’ll work on that.
    • Trying to decide how many suggestions around using AI I should include.
      • It’s not mentioned in the book yet, but I think I need to incorporate some discussion around it.

Michael:

Joke: Reverse Superman





Download audio: https://pythonbytes.fm/episodes/download/466/psf-lands-1.5-million.mp3
Read the whole story
alvinashcraft
7 hours ago
reply
Pennsylvania, USA
Share this story
Delete

Convert CSV to PDF in .NET C#

1 Share
Learn how to convert CSV data to a table in C# using the ServerTextControl library with this step-by-step tutorial. Easily generate PDF documents from CSV files in your .NET applications.

Read the whole story
alvinashcraft
7 hours ago
reply
Pennsylvania, USA
Share this story
Delete

Step-by-Step Guide: Build a CRUD Blazor App with Entity Framework and PostgreSQL

1 Share

Introduction

Happy New Year 2026 to all! This year, I want to share more basic must-learn knowledge on .NET. This tutorial is my first sharing on dev.to this year. Happy to see you all again.

Entity Framework (EF) is Microsoft's object-relational mapper (ORM) for .NET. It simplifies data access by allowing you to work with databases using .NET objects, eliminating the need for most data-access code. In this tutorial, we'll build a simple CRUD (Create, Read, Update, Delete) Blazor Server app using EF Core with PostgreSQL. We'll cover setting up the project, defining models, seeding data, and creating a basic UI for managing customers.

By the end, you'll have a functional app demonstrating EF's power for database operations.

Prerequisites

Before we begin, ensure you have the following:

  • Visual Studio or any C# IDE (e.g., VS Code).
  • .NET 10 SDK installed (download from Microsoft's site).
  • PostgreSQL installed and running (download from EnterpriseDB). Set up a database (e.g., "BlazorDemo") and note the connection details.

Step 1: Setting Up the Blazor Project

Create a new Blazor Server app:

dotnet new blazorserver --force

This scaffolds a basic Blazor Server project.

Step 2: Adding Entity Framework Packages

Add the necessary NuGet packages for EF Core and PostgreSQL:

dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.Tools
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
  • Microsoft.EntityFrameworkCore: Core EF functionality.
  • Microsoft.EntityFrameworkCore.Tools: For migrations and database commands.
  • Npgsql.EntityFrameworkCore.PostgreSQL: PostgreSQL provider.

Step 3: Creating Models

Define your data models. Create a Models folder and add classes like Customer.cs:

using System.ComponentModel.DataAnnotations;

namespace BlazorWithEntityFramework.Models
{
    public class Customer
    {
        [Key]
        public long CustomerId { get; set; }

        [Required]
        [StringLength(1000)]
        public string CustomerNumber { get; set; } = string.Empty;

        [Required]
        [StringLength(100)]
        public string LastName { get; set; } = string.Empty;

        [Required]
        [StringLength(100)]
        public string FirstName { get; set; } = string.Empty;

        [Required]
        public DateTime Dob { get; set; }

        public bool IsDeleted { get; set; } = false;

        [StringLength(100)]
        public string CreateBy { get; set; } = "SYSTEM";

        public DateTime CreateDate { get; set; } = DateTime.UtcNow;

        [StringLength(100)]
        public string ModifyBy { get; set; } = "SYSTEM";

        public DateTime ModifyDate { get; set; } = DateTime.UtcNow;
    }
}

Product.cs:

using System.ComponentModel.DataAnnotations;

namespace BlazorWithEntityFramework.Models
{
    public class Product
    {
        [Key]
        public long ProductId { get; set; }

        [Required]
        [StringLength(1000)]
        public string ProductName { get; set; } = string.Empty;

        [Required]
        [StringLength(1000)]
        public string ProductCode { get; set; } = string.Empty;

        [Required]
        [Range(0, int.MaxValue)]
        public int AvailableQuantity { get; set; }

        public bool IsDeleted { get; set; } = false;

        [StringLength(100)]
        public string CreateBy { get; set; } = "SYSTEM";

        public DateTime CreateDate { get; set; } = DateTime.UtcNow;

        [StringLength(100)]
        public string ModifyBy { get; set; } = "SYSTEM";

        public DateTime ModifyDate { get; set; } = DateTime.UtcNow;

        public ICollection<OrderItem> OrderItems { get; set; } = new List<OrderItem>();
    }
}

Order.cs:

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace BlazorWithEntityFramework.Models
{
    public class Order
    {
        [Key]
        public long OrderId { get; set; }

        public long? CustomerId { get; set; }

        [Required]
        [StringLength(1000)]
        public string OrderNumber { get; set; } = string.Empty;

        [Required]
        public DateTime OrderDate { get; set; }

        public bool IsDeleted { get; set; } = false;

        [StringLength(100)]
        public string CreateBy { get; set; } = "SYSTEM";

        public DateTime CreateDate { get; set; } = DateTime.UtcNow;

        [StringLength(100)]
        public string ModifyBy { get; set; } = "SYSTEM";

        public DateTime ModifyDate { get; set; } = DateTime.UtcNow;

        [ForeignKey("CustomerId")]
        public Customer? Customer { get; set; }

        public ICollection<OrderItem> OrderItems { get; set; } = new List<OrderItem>();
    }
}

OrderItem.cs:

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace BlazorWithEntityFramework.Models
{
    public class OrderItem
    {
        [Key]
        public long OrderItemId { get; set; }

        public long? OrderId { get; set; }

        public long? ProductId { get; set; }

        [Required]
        [Range(1, int.MaxValue)]
        public int Quantity { get; set; }

        public bool IsDeleted { get; set; } = false;

        [StringLength(100)]
        public string CreateBy { get; set; } = "SYSTEM";

        public DateTime CreateDate { get; set; } = DateTime.UtcNow;

        [StringLength(100)]
        public string ModifyBy { get; set; } = "SYSTEM";

        public DateTime ModifyDate { get; set; } = DateTime.UtcNow;

        [ForeignKey("OrderId")]
        public Order? Order { get; set; }

        [ForeignKey("ProductId")]
        public Product? Product { get; set; }
    }
}

Step 4: Setting Up the DbContext

Create a Data folder and add AppDbContext.cs:

using Microsoft.EntityFrameworkCore;
using BlazorWithEntityFramework.Models;

namespace BlazorWithEntityFramework.Data
{
    public class AppDbContext : DbContext
    {
        public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }

        public DbSet<Customer> Customers { get; set; }
        public DbSet<Product> Products { get; set; }
        public DbSet<Order> Orders { get; set; }
        public DbSet<OrderItem> OrderItems { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            // Seed data
            modelBuilder.Entity<Customer>().HasData(
                new Customer
                {
                    CustomerId = 1,
                    CustomerNumber = "CUST0001",
                    LastName = "Au Yeung",
                    FirstName = "David",
                    Dob = new DateTime(1980, 12, 31, 0, 0, 0, DateTimeKind.Utc),
                    IsDeleted = false,
                    CreateBy = "SYSTEM",
                    CreateDate = DateTime.UtcNow,
                    ModifyBy = "SYSTEM",
                    ModifyDate = DateTime.UtcNow
                },
                new Customer
                {
                    CustomerId = 2,
                    CustomerNumber = "CUST0002",
                    LastName = "Chan",
                    FirstName = "Peter",
                    Dob = new DateTime(1982, 1, 15, 0, 0, 0, DateTimeKind.Utc),
                    IsDeleted = false,
                    CreateBy = "SYSTEM",
                    CreateDate = DateTime.UtcNow,
                    ModifyBy = "SYSTEM",
                    ModifyDate = DateTime.UtcNow
                }
            );

            modelBuilder.Entity<Product>().HasData(
                new Product
                {
                    ProductId = 1,
                    ProductName = "Android Phone",
                    ProductCode = "A0001",
                    AvailableQuantity = 100,
                    IsDeleted = false,
                    CreateBy = "SYSTEM",
                    CreateDate = DateTime.UtcNow,
                    ModifyBy = "SYSTEM",
                    ModifyDate = DateTime.UtcNow
                },
                new Product
                {
                    ProductId = 2,
                    ProductName = "iPhone",
                    ProductCode = "I0001",
                    AvailableQuantity = 100,
                    IsDeleted = false,
                    CreateBy = "SYSTEM",
                    CreateDate = DateTime.UtcNow,
                    ModifyBy = "SYSTEM",
                    ModifyDate = DateTime.UtcNow
                }
            );

            modelBuilder.Entity<Order>().HasData(
                new Order
                {
                    OrderId = 1,
                    CustomerId = 1,
                    OrderNumber = "ORD0001",
                    OrderDate = DateTime.UtcNow,
                    IsDeleted = false,
                    CreateBy = "SYSTEM",
                    CreateDate = DateTime.UtcNow,
                    ModifyBy = "SYSTEM",
                    ModifyDate = DateTime.UtcNow
                }
            );

            modelBuilder.Entity<OrderItem>().HasData(
                new OrderItem
                {
                    OrderItemId = 1,
                    OrderId = 1,
                    ProductId = 2,
                    Quantity = 10,
                    IsDeleted = false,
                    CreateBy = "SYSTEM",
                    CreateDate = DateTime.UtcNow,
                    ModifyBy = "SYSTEM",
                    ModifyDate = DateTime.UtcNow
                }
            );
        }
    }
}

Step 5: Configuring the Connection String

In appsettings.json, add:

{
  "ConnectionStrings": {
    "DefaultConnection": "Host=localhost;Database=BlazorDemo;Username=yourusername;Password=yourpassword"
  }
}

Update Program.cs to register the DbContext:

builder.Services.AddDbContext<AppDbContext>(options => options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));

And ensure DB creation:

using (var scope = app.Services.CreateScope())
{
    var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
    db.Database.EnsureCreated();
}

Step 6: Creating Migrations and Updating the Database

Generate and apply migrations:

dotnet ef migrations add InitialCreate
dotnet ef database update

EnsureCreated() in Program.cs ensures the database is created and seeded on startup. This works alongside migrations for a demo. Note that in production, you might prefer migrations exclusively for better control.

Step 7: Building the CRUD UI

Create a page like Pages/Customers.razor for managing customers:

@page "/customers"
@inject AppDbContext DbContext

<h3>Customers</h3>

@if (customers == null)
{
    <p>Loading...</p>
}
else
{
    <table class="table">
        <thead>
            <tr>
                <th>ID</th>
                <th>Customer Number</th>
                <th>Last Name</th>
                <th>First Name</th>
                <th>DOB</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var customer in customers.Where(c => !c.IsDeleted))
            {
                <tr>
                    <td>@customer.CustomerId</td>
                    <td>@customer.CustomerNumber</td>
                    <td>@customer.LastName</td>
                    <td>@customer.FirstName</td>
                    <td>@customer.Dob.ToShortDateString()</td>
                    <td>
                        <button class="btn btn-primary" @onclick="() => EditCustomer(customer)">Edit</button>
                        <button class="btn btn-danger" @onclick="() => DeleteCustomer(customer)">Delete</button>
                    </td>
                </tr>
            }
        </tbody>
    </table>

    <button class="btn btn-success" @onclick="AddCustomer">Add New Customer</button>

    @if (isEditing)
    {
        <div class="modal" style="display:block;">
            <div class="modal-content">
                <h4>@(editingCustomer.CustomerId == 0 ? "Add" : "Edit") Customer</h4>
                <form>
                    <div class="form-group">
                        <label>Customer Number</label>
                        <input type="text" class="form-control" @bind="editingCustomer.CustomerNumber" />
                    </div>
                    <div class="form-group">
                        <label>Last Name</label>
                        <input type="text" class="form-control" @bind="editingCustomer.LastName" />
                    </div>
                    <div class="form-group">
                        <label>First Name</label>
                        <input type="text" class="form-control" @bind="editingCustomer.FirstName" />
                    </div>
                    <div class="form-group">
                        <label>DOB</label>
                        <input type="date" class="form-control" @bind="editingCustomer.Dob" />
                    </div>
                    <button type="button" class="btn btn-primary" @onclick="SaveCustomer">Save</button>
                    <button type="button" class="btn btn-secondary" @onclick="CancelEdit">Cancel</button>
                </form>
            </div>
        </div>
    }
}

@code {
    private List<Customer> customers = new();
    private Customer editingCustomer = new();
    private bool isEditing = false;

    protected override async Task OnInitializedAsync()
    {
        await LoadCustomers();
    }

    private async Task LoadCustomers()
    {
        customers = await DbContext.Customers.AsNoTracking().ToListAsync();
    }

    private void AddCustomer()
    {
        editingCustomer = new Customer { Dob = DateTime.UtcNow };
        isEditing = true;
    }

    private void EditCustomer(Customer customer)
    {
        editingCustomer = new Customer
        {
            CustomerId = customer.CustomerId,
            CustomerNumber = customer.CustomerNumber,
            LastName = customer.LastName,
            FirstName = customer.FirstName,
            Dob = customer.Dob,
            IsDeleted = customer.IsDeleted,
            CreateBy = customer.CreateBy,
            CreateDate = customer.CreateDate,
            ModifyBy = "USER",
            ModifyDate = DateTime.UtcNow
        };
        isEditing = true;
    }

    private async Task SaveCustomer()
    {
        if (editingCustomer.CustomerId == 0)
        {
            DbContext.Customers.Add(editingCustomer);
        }
        else
        {
            var existing = await DbContext.Customers.FindAsync(editingCustomer.CustomerId);
            if (existing != null)
            {
                DbContext.Entry(existing).CurrentValues.SetValues(editingCustomer);
            }
        }
        await DbContext.SaveChangesAsync();
        isEditing = false;
        await LoadCustomers();
    }

    private void CancelEdit()
    {
        isEditing = false;
    }

    private async Task DeleteCustomer(Customer customer)
    {
        var existing = await DbContext.Customers.FindAsync(customer.CustomerId);
        if (existing != null)
        {
            existing.IsDeleted = true;
            existing.ModifyBy = "USER";
            existing.ModifyDate = DateTime.UtcNow;
            DbContext.Customers.Update(existing);
        }
        await DbContext.SaveChangesAsync();
        await LoadCustomers();
    }
}

Add navigation in NavMenu.razor.

Step 8: Running the App

Run the app:

dotnet run

Navigate to /customers to test CRUD operations.

Conclusion

You've built a CRUD Blazor app with EF and PostgreSQL! EF simplifies database interactions, and Blazor provides a seamless UI. Experiment with more entities or features like validation.

Feel free to ask questions or expand on this. Happy coding!

Love C#!

Read the whole story
alvinashcraft
7 hours ago
reply
Pennsylvania, USA
Share this story
Delete

The Introvert’s Guide to Networking: How I Stopped Faking It and Started Growing

1 Share

The "Alien" Phase

For a long time, I felt like an alien.

I’m naturally reserved. I’m not the loudest person in the room, and for years, I thought that was a defect. I grew up surrounded by people who didn't really get me. I found myself forcing an interest in things the "masses" liked, such as trends, generic hobbies, and surface-level conversations, just to survive social situations.

I was masking my true self to fit in, and it was exhausting. I thought, “Maybe I’m just not built for connecting with people.”

I wasn't anti-social, I just didn't have a social circle that spoke my language. I was starving for intellectual connection but looking for it in all the wrong places.

Finding My Voice on Dev.to

Then, I started writing here.

Initially, I thought Dev.to was just a place to dump code snippets. But as I began sharing my personal experiences, my learning journey, and my struggles, something shifted.

I realized I wasn't shouting into the void. I was speaking into a room full of people just like me.

Writing allowed me to express myself in a way speaking never did. It gave me the space to articulate my thoughts without being interrupted or feeling the pressure to be "cool." Suddenly, my obsession with tech, my curiosity about how things work, and my specific interests weren't "weird." They were the currency of this community.

The "ROI" of Putting Yourself Out There

Here is the crazy part: Networking doesn't always happen in a suit at a conference center. Sometimes it happens in the comment section.

Since I started consistently sharing my journey and being vulnerable about what I’m learning:

I’ve connected with amazing developers who share my niche interests.

I’ve had recruiters slide into my DMs because they liked how I explained a concept.

I’ve even landed paid freelance gigs purely because someone saw a post of mine and thought, "This person knows their stuff, and I like their vibe."

I didn't have to change who I was. I just had to change where I was speaking.

The Next Step: Stepping Into the Real World

Because this platform gave me the confidence to believe that my voice matters, I’m challenging myself to take the next step.

I am going to start attending in-person tech events.

Yes, as an introvert, the idea is terrifying. But now I know that when I walk into those rooms, I’m not walking in as an alien. I’m walking into a room full of potential readers, friends, and collaborators.

What’s Coming Next?

I want to take you along for this ride.

The DevOps Journey Series: I will continue writing my technical series on Linux and my journey to devOps (which I love writing), so stay tuned for those deep dives.

The Event Series: I will be starting a new series documenting my experiences at these in-person tech events. I’ll share what it’s actually like, how I handle the nerves, and who I meet.

You Are Not Alone!

If you are reading this and you feel like the "alien" in your circle, please know you aren't alone.

There is a massive community of people here who are interested in the exact same things you are. You don't need to force yourself to like what the masses like. You just need to find your tribe.

Start writing. Start sharing. You’ll be surprised who writes back :)

Read the whole story
alvinashcraft
7 hours ago
reply
Pennsylvania, USA
Share this story
Delete
Next Page of Stories