# Entity Seeding Pattern

> Reference: See `templates-seed.md` section "TEMPLATE: ENTITY SEED DATA (SeedData Provider)"

## SeedData File

**`Infrastructure/Persistence/Seeding/Data/{Domain}/{EntityName}SeedData.cs`**

Follow SmartStack.app pattern:
- Static class with `internal static IEnumerable<{EntityName}SeedItem> GetAll{EntityName}s()`
- Use deterministic GUIDs (NEVER `Guid.NewGuid()`)
- Include 3-5 sample entities with varied, realistic data
- For multi-tenant: organize by tenant using `GetTenant1{EntityName}s()` helpers

```csharp
public static class {EntityName}SeedData
{
    public static readonly Guid Sample1Id = Guid.Parse("...");
    public static readonly Guid Sample2Id = Guid.Parse("...");
    public static readonly Guid Sample3Id = Guid.Parse("...");

    internal static IEnumerable<{EntityName}SeedItem> GetAll{EntityName}s()
    {
        return new[]
        {
            new {EntityName}SeedItem { Id = Sample1Id, /* ... */ },
            new {EntityName}SeedItem { Id = Sample2Id, /* ... */ },
            new {EntityName}SeedItem { Id = Sample3Id, /* ... */ }
        };
    }
}

internal class {EntityName}SeedItem
{
    public Guid Id { get; init; }
    // ... all required entity properties
}
```

## DevDataSeeder Update

Add to `Infrastructure/Persistence/Seeding/DevDataSeeder.cs`:
- `using` for the new SeedData namespace
- `await Seed{EntityName}sAsync(cancellationToken);` in `SeedAsync()` method

```csharp
private async Task Seed{EntityName}sAsync(CancellationToken cancellationToken)
{
    _logger.LogInformation("Seeding demo {EntityName}s...");

    var existingCount = await _context.{EntityName}s.CountAsync(cancellationToken);
    if (existingCount > 0)
    {
        _logger.LogWarning("{EntityName}s already seeded ({Count} exist), skipping.", existingCount);
        return;
    }

    var createdCount = 0;
    foreach (var seedItem in {EntityName}SeedData.GetAll{EntityName}s())
    {
        var entity = {EntityName}.Create(/* map seedItem properties */);
        typeof({EntityName}).GetProperty("Id")?.SetValue(entity, seedItem.Id);
        _context.{EntityName}s.Add(entity);
        createdCount++;
    }

    if (createdCount > 0)
        await _context.SaveChangesAsync(cancellationToken);

    _logger.LogInformation("Created {Count} demo {EntityName}s.", createdCount);
}
```
