Search code examples
c#entity-frameworkmappingtuplescode-first

How to map Tuple<something, something> to database using c# EF code first?


i've been searching and can't find anything to solve my problem, here is part of my code:

namespace Domain
{
    public class Assessment
    {
        //Other Props
        public List<Tuple<User, int>> UsersMeantToSolveThisAlongWithTimeEachSpentOnIt { get; set; }
    }
}

When I modify the database using migrations everything is mapped correctly, simple props get into "Assessments" table perfectly, and some props which use other entities in a "many to many" way, are correctly mapped into new tables after using Fluent API.

Yet i don't know how to map this list of tuples... any ideas?


Solution

  • Well, i came up with a solution, if anyone has the same problem, i ended up doing this:

    1 - created a new class

    public class UserAndTimeHeSpentOnSolvingAssessment
    {
        public int Id { get; set; }
        public User UserSolvingTheAssessment { get; set; }
        public int TimeSpentByUserToSolveTheAssessment { get; set; }
    }
    

    2 - update my disturbing property

    public List<UserAndTimeHeSpentOnSolvingAssessment> UsersMeantToSolveThisAlongWithTimeEachSpentOnIt { get; set; }
    

    It worked, yet i still have doubt about mapping tuples, if anyone knows the answer i will most welcome it :D