# 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()`
- ALWAYS use `Guid.NewGuid()` — avoids conflicts between projects/tenants/environments
- Idempotence is handled by `AnyAsync()` checks (by Code/Name), NOT by fixed IDs
- 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.NewGuid();
    public static readonly Guid Sample2Id = Guid.NewGuid();
    public static readonly Guid Sample3Id = Guid.NewGuid();

    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 */);
        // Factory method generates a random GUID — no need to override
        _context.{EntityName}s.Add(entity);
        createdCount++;
    }

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

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