# EF Core Troubleshooting

## Database Status

### Troubleshooting (if connection fails)

```
TROUBLESHOOTING
├── SQL Server running?
├── appsettings.Local.json configured?
├── Database exists?
└── Commands: /efcore db-reset, /efcore db-deploy
```

## Deploy Errors

| Error | Resolution |
|-------|------------|
| Connection failed | Check SQL Server, credentials |
| Migration error | Review migration, consider reset |
| Constraint violation | Check data, may need seed |

## Reset Protections

| Protection | Description |
|------------|-------------|
| Env Display | Shows database BEFORE confirmation |
| Confirmation | Explicit request with database NAME |
| Production Block | Blocks if Production detected |
| EF Core Only | No raw SQL |

## Seed Setup Guide

If no seed methods detected, display guide:

```
SEED SETUP GUIDE
================

Option 1: HasData() in Configuration (RECOMMENDED)
--------------------------------------------------
// In UserConfiguration.cs
builder.HasData(new User {
    Id = Guid.NewGuid(),
    Name = "Admin",
    Email = "admin@example.com"
});

// Then run:
dotnet ef migrations add SeedData

Option 2: IDataSeeder Class
---------------------------
public class UserSeeder : IDataSeeder
{
    public async Task SeedAsync(DbContext context)
    {
        if (!await context.Users.AnyAsync())
        {
            context.Users.Add(new User { ... });
            await context.SaveChangesAsync();
        }
    }
}

// Register in Program.cs and call via --seed argument
```

## Migration from SQL

```csharp
// BEFORE (FORBIDDEN): scripts/seed.sql
INSERT INTO Users (Id, Name) VALUES (1, 'Admin');

// AFTER (CORRECT): UserConfiguration.cs
builder.HasData(new User {
    Id = Guid.NewGuid(),
    Name = "Admin"
});
// Then: dotnet ef migrations add SeedData
```
