C#C
C#3y ago
poopkaka

❔ Entity Framework

im trying to make spotify like application but anytime i try to get the user who created the playlist it turns up null.

public List<PlaylistDTO> GetAllPlaylists()
        { 
            using (var db = new SurroundDbContext())
            {
                return db.Playlists.Include(p => p.Creator).ToList();
            }
        }


public class PlaylistDTO
    {
        [Key]
        public int Id { get; set; }
        public string Name { get; set; } = null!;
        public ICollection<SongDTO> Songs { get; set; } = null!;
        [ForeignKey("UserId")]
        public int CreatorId { get; set; }
        public UserDTO Creator { get; set; } = null!;
    }

public class UserDTO
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int UserID { get; set; }
        public string? Username { get; set; }
        public string? Email { get; set; }
        public string? Password { get; set; }
        public string? VerPass;
        public DateTime CreatedDate { get; set; }
        public ICollection<PlaylistDTO> PlayLists { get; set; } = null!;
    }
Was this page helpful?