Create EF Core entity models with relationships #60

Closed
opened 2026-01-18 22:29:33 +00:00 by joezombie · 1 comment
joezombie commented 2026-01-18 22:29:33 +00:00 (Migrated from github.com)

Parent Epic

Part of #58 - Migrate to Entity Framework Core

Description

Create proper EF Core entity classes to replace the current record models, with navigation properties and data annotations.

Entity Models

Feed Entity

// Data/Entities/Feed.cs
public class Feed
{
    public int Id { get; set; }
    
    [Required, MaxLength(100)]
    public string Name { get; set; } = string.Empty;
    
    [Required, MaxLength(500)]
    public string Title { get; set; } = string.Empty;
    
    [Required]
    public string Description { get; set; } = string.Empty;
    
    [Required, MaxLength(1000)]
    public string Directory { get; set; } = string.Empty;
    
    [MaxLength(200)]
    public string? Author { get; set; }
    
    [MaxLength(1000)]
    public string? ImageUrl { get; set; }
    
    [MaxLength(1000)]
    public string? Link { get; set; }
    
    [MaxLength(10)]
    public string Language { get; set; } = "en-us";
    
    [MaxLength(100)]
    public string? Category { get; set; }
    
    [MaxLength(100)]
    public string FileExtensions { get; set; } = ".mp3";
    
    // YouTube configuration
    [MaxLength(500)]
    public string? YouTubePlaylistUrl { get; set; }
    public int YouTubePollIntervalMinutes { get; set; } = 60;
    public bool YouTubeEnabled { get; set; }
    public int YouTubeMaxConcurrentDownloads { get; set; } = 1;
    [MaxLength(20)]
    public string YouTubeAudioQuality { get; set; } = "highest";
    
    public DateTime CreatedAt { get; set; }
    public DateTime UpdatedAt { get; set; }
    public bool IsActive { get; set; } = true;
    
    // Navigation properties
    public ICollection<Episode> Episodes { get; set; } = new List<Episode>();
    public ICollection<DownloadedVideo> DownloadedVideos { get; set; } = new List<DownloadedVideo>();
    public ICollection<ActivityLog> ActivityLogs { get; set; } = new List<ActivityLog>();
    public ICollection<DownloadQueueItem> DownloadQueue { get; set; } = new List<DownloadQueueItem>();
}

Episode Entity

// Data/Entities/Episode.cs
public class Episode
{
    public int Id { get; set; }
    public int FeedId { get; set; }
    
    [Required, MaxLength(500)]
    public string Filename { get; set; } = string.Empty;
    
    [MaxLength(50)]
    public string? VideoId { get; set; }
    
    [MaxLength(500)]
    public string? YoutubeTitle { get; set; }
    
    public string? Description { get; set; }
    
    [MaxLength(1000)]
    public string? ThumbnailUrl { get; set; }
    
    public int DisplayOrder { get; set; }
    public DateTime AddedAt { get; set; }
    public DateTime? PublishDate { get; set; }
    public double? MatchScore { get; set; }
    
    // Navigation property
    public Feed Feed { get; set; } = null!;
}

Other Entities

  • DownloadedVideo - Tracks downloaded YouTube videos
  • ActivityLog - Activity history for monitoring
  • DownloadQueueItem - Active download queue

Entity Configurations

Use Fluent API for complex configurations:

// Data/Configurations/EpisodeConfiguration.cs
public class EpisodeConfiguration : IEntityTypeConfiguration<Episode>
{
    public void Configure(EntityTypeBuilder<Episode> builder)
    {
        builder.HasIndex(e => new { e.FeedId, e.Filename }).IsUnique();
        builder.HasIndex(e => e.VideoId);
        builder.HasIndex(e => new { e.FeedId, e.DisplayOrder });
        
        builder.HasOne(e => e.Feed)
            .WithMany(f => f.Episodes)
            .HasForeignKey(e => e.FeedId)
            .OnDelete(DeleteBehavior.Cascade);
    }
}

Tasks

  • Create Data/Entities/ folder
  • Implement Feed entity with all properties
  • Implement Episode entity with relationship
  • Implement DownloadedVideo entity
  • Implement ActivityLog entity
  • Implement DownloadQueueItem entity
  • Create configuration classes in Data/Configurations/
  • Update DbContext to use new entities
  • Add proper indexes and constraints

Acceptance Criteria

  • All entities have proper data annotations
  • Relationships defined with navigation properties
  • Indexes match current database schema
  • Foreign key cascades configured correctly
## Parent Epic Part of #58 - Migrate to Entity Framework Core ## Description Create proper EF Core entity classes to replace the current record models, with navigation properties and data annotations. ## Entity Models ### Feed Entity ```csharp // Data/Entities/Feed.cs public class Feed { public int Id { get; set; } [Required, MaxLength(100)] public string Name { get; set; } = string.Empty; [Required, MaxLength(500)] public string Title { get; set; } = string.Empty; [Required] public string Description { get; set; } = string.Empty; [Required, MaxLength(1000)] public string Directory { get; set; } = string.Empty; [MaxLength(200)] public string? Author { get; set; } [MaxLength(1000)] public string? ImageUrl { get; set; } [MaxLength(1000)] public string? Link { get; set; } [MaxLength(10)] public string Language { get; set; } = "en-us"; [MaxLength(100)] public string? Category { get; set; } [MaxLength(100)] public string FileExtensions { get; set; } = ".mp3"; // YouTube configuration [MaxLength(500)] public string? YouTubePlaylistUrl { get; set; } public int YouTubePollIntervalMinutes { get; set; } = 60; public bool YouTubeEnabled { get; set; } public int YouTubeMaxConcurrentDownloads { get; set; } = 1; [MaxLength(20)] public string YouTubeAudioQuality { get; set; } = "highest"; public DateTime CreatedAt { get; set; } public DateTime UpdatedAt { get; set; } public bool IsActive { get; set; } = true; // Navigation properties public ICollection<Episode> Episodes { get; set; } = new List<Episode>(); public ICollection<DownloadedVideo> DownloadedVideos { get; set; } = new List<DownloadedVideo>(); public ICollection<ActivityLog> ActivityLogs { get; set; } = new List<ActivityLog>(); public ICollection<DownloadQueueItem> DownloadQueue { get; set; } = new List<DownloadQueueItem>(); } ``` ### Episode Entity ```csharp // Data/Entities/Episode.cs public class Episode { public int Id { get; set; } public int FeedId { get; set; } [Required, MaxLength(500)] public string Filename { get; set; } = string.Empty; [MaxLength(50)] public string? VideoId { get; set; } [MaxLength(500)] public string? YoutubeTitle { get; set; } public string? Description { get; set; } [MaxLength(1000)] public string? ThumbnailUrl { get; set; } public int DisplayOrder { get; set; } public DateTime AddedAt { get; set; } public DateTime? PublishDate { get; set; } public double? MatchScore { get; set; } // Navigation property public Feed Feed { get; set; } = null!; } ``` ### Other Entities - `DownloadedVideo` - Tracks downloaded YouTube videos - `ActivityLog` - Activity history for monitoring - `DownloadQueueItem` - Active download queue ## Entity Configurations Use Fluent API for complex configurations: ```csharp // Data/Configurations/EpisodeConfiguration.cs public class EpisodeConfiguration : IEntityTypeConfiguration<Episode> { public void Configure(EntityTypeBuilder<Episode> builder) { builder.HasIndex(e => new { e.FeedId, e.Filename }).IsUnique(); builder.HasIndex(e => e.VideoId); builder.HasIndex(e => new { e.FeedId, e.DisplayOrder }); builder.HasOne(e => e.Feed) .WithMany(f => f.Episodes) .HasForeignKey(e => e.FeedId) .OnDelete(DeleteBehavior.Cascade); } } ``` ## Tasks - [ ] Create `Data/Entities/` folder - [ ] Implement Feed entity with all properties - [ ] Implement Episode entity with relationship - [ ] Implement DownloadedVideo entity - [ ] Implement ActivityLog entity - [ ] Implement DownloadQueueItem entity - [ ] Create configuration classes in `Data/Configurations/` - [ ] Update DbContext to use new entities - [ ] Add proper indexes and constraints ## Acceptance Criteria - [ ] All entities have proper data annotations - [ ] Relationships defined with navigation properties - [ ] Indexes match current database schema - [ ] Foreign key cascades configured correctly
joezombie commented 2026-01-26 22:25:30 +00:00 (Migrated from github.com)

Completed: Created 5 EF Core entity models (Feed, Episode, DownloadedVideo, DownloadQueueItem, ActivityLog) with proper relationships and Fluent API configurations using snake_case column naming.

Completed: Created 5 EF Core entity models (Feed, Episode, DownloadedVideo, DownloadQueueItem, ActivityLog) with proper relationships and Fluent API configurations using snake_case column naming.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
joezombie/castr#60
No description provided.