none
EF 4.3 NullReferenceException using Annotations InverseProperty and ForeignKey RRS feed

  • Question

  • Hello,

    using EF 4.3 Code First

    I want to design two optional relations between two classes:

    After reading Entity Framework 4.1 InverseProperty Attribute and ForeignKey I designed my classes:

    <Table("Person")>
    public class Person
    
    <InverseProperty("QuestioningPerson")>
    Public Overridable Property QuestionnaireResponseQuestioningList As ICollection(Of QuestionnaireResponse)
    
    <InverseProperty("AnsweringPerson")>
    Public Overridable Property QuestionnaireResponseAnsweringList As ICollection(Of QuestionnaireResponse)
    
    end class
    
    
    public class QuestionnaireResponse
    
    <ForeignKey("QuestioningPerson")>
    Public Property QuestioningPerson_Id As Guid
    
    <ForeignKey("AnsweringPerson")>
    Public Property AnsweringPerson_Id As Guid
    
    <InverseProperty("QuestionnaireResponseQuestioningList")>
    Public Overridable Property QuestioningPerson As Person
        
    <InverseProperty("QuestionnaireResponseAnsweringList")>
    Public Overridable Property AnsweringPerson As Person
    
    end class

    I received NullReferenceExceptio...

    reading  Using InverseProperty on self-referencing entity in 4.3 

    I tried with one of that relations removing the InverseProperty Annotations...Building was possible --> creating a required relation.

    Should i rather use FluentAPI?

    Wednesday, March 28, 2012 12:25 PM

All replies

  • Hi Cortadillo,

    Welcome to MSDN Forum.

    Could you please clarify where the NullReferenceException is thrown?

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 30, 2012 3:06 AM
    Moderator
  • Hi Cortadillo,

    Have you solved the issue? I look forward to hearing from you.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 2, 2012 1:42 AM
    Moderator