Multiple relationships of to same type throws IncorrectRelationshipException
Issue #23
resolved
Using the following classes:
[Table("ExerciseMultipleChoiceSentence")]
public class ExerciseMultipleChoiceSentence
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[ForeignKey(typeof(Sentence))]
public int QuestionSentenceId { get; set; }
[OneToOne]
public Sentence QuestionSentence { get; set; }
[ManyToMany(typeof(SentenceExerciseMultipleChoiceSentence))]
public Sentence[] IncorrectAnswerSentences { get; set; }
}
[Table("Sentence")]
public class Sentence
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string English { get; set; }
[ManyToMany(typeof(SentenceExerciseMultipleChoiceSentence))]
public ExerciseMultipleChoiceSentence[] ExerciseMultipleChoiceSentences { get; set; }
[Table("SentenceExerciseMultipleChoiceSentence")]
public class SentenceExerciseMultipleChoiceSentence
{
[ForeignKey(typeof(Sentence))]
public int SentenceId { get; set; }
[ForeignKey(typeof(ExerciseMultipleChoiceSentence))]
public int ExerciseId { get; set; }
}
Attempting to create and insert data throws an IncorrectRelationshipException when inserting a ExerciseMultipleChoiceSentence
Comments (3)
-
-
reporter That does help, thank you :)
-
- changed status to resolved
- Log in to comment
The problem is that the library tries to locate the inverse relationship for
Sentence. ExerciseMultipleChoiceSentences
and it will find aOneToOne
relationship first, instead of theManyToMany
.This error will be fixed as soon as the Issue #17 is implemented, that will improve discovery of inverse relationships. Until then, you can simply specify the inverse relationship manually like this:
In
Sentence
:And in
ExerciseMultipleChoiceSentence
, set the inverse property to""
to let the library know that it doesn't have any inverse property:Hope it helps.