Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two entities
1.Status
2.ActionProgress

In status entity,i want to become composite keys/
C#
public class Status
 {
     [Key, Column(Order = 0)]       
     public int Id { get; set; }
     public string Name { get; set; }   
     [Key, Column(Order = 1)]
     public int LanguageId { get; set; }    
     [ForeignKey("LanguageId")]
     public virtual Language Language { get; set; }
 }

and other entity is
SQL
public class ActionProgress
   {
       [Key,Column(Order=0)]
       [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
       public int ActionProgressID { get; set; }     
    
       public int? StatusID { get; set; }    
      
       [ForeignKey("StatusID")]
       public virtual Status ActionProgressStatus { get; set; }
   }


i am using code first approach.when i run my application,
the error is throwing,
"The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical."


i don't know what i am doing wrong.please help
Posted
Updated 21-Apr-15 0:54am
v4
Comments
johannesnestler 30-Apr-15 8:40am    
did you solve it?

1 solution

I do all my entity configuration with the fluent API
(where I could write
...HasForeignKey(e => new { e.ID, e.LanguageID })

I think the equivalent with dataanotations would be:
C#
public class ActionProgress
   {
       [Key,Column(Order=0)]
       [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
       public int ActionProgressID { get; set; }

       [ForeignKey("ActionProgressStatus", Column(Order = 0)]
       public int? StatusID { get; set; }
       [ForeignKey("ActionProgressStatus", Column(Order = 1))]
       public int? StatusLanguageID { get; set; }

       public virtual Status ActionProgressStatus { get; set; }
   }


Please try for yourself... Would be nice if you leave a note if it worked...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900