© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
20 replies
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!;
    }
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!;
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Entity framework
C#CC# / help
14mo ago
❔ Entity Framework
C#CC# / help
3y ago
Entity Framework Entity Saving
C#CC# / help
11mo ago
Entity Framework - MODEL and ENTITY
C#CC# / help
4y ago