Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 928
Alvaro Rodriguez Scelza Avatar asked Oct 21 '25 15:10

Alvaro Rodriguez Scelza


1 Answers

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

like image 99
Alvaro Rodriguez Scelza Avatar answered Oct 23 '25 07:10

Alvaro Rodriguez Scelza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!