Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Composite keys #6607


User avatar
0
affern created

Hi again guys. I have created a domain class with a composite keys:

    public class MultiAnswer 
    {

        [Key]
        [Column(Order = 1)]
        public long SurveyId { get; set; }
        [Key]
        [Column(Order = 2)]
        public long UserId { get; set; }
     
        [Key]
        [Column(Order = 3)]
        public int ItemId { get; set; }
      
        [Required]       
        public int AnswerId { get; set; }
                       
        public DateTime DateAnswer { get; set; }
        
        [ForeignKey("SurveyId")]
        public virtual Survey Survey { get; set; }

    }

But how do I declare a MultiAnswer Repository with 3 keys? The IRepository is for one primary key.


4 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    But how do I declare a MultiAnswer Repository with 3 keys?

    You cannot.

    The IRepository is for one primary key.

    Exactly.

  • User Avatar
    0
    affern created

    So the best solution is to create a new MultiAnswerRepository class and a IMultiAnswerRepository interface and solve this dependency injection separatley?

  • User Avatar
    0
    aaron created
    Support Team

    Yes.

  • User Avatar
    0
    affern created

    Ok. Thanks :-)