The navigation property 'SenderId' is not a declared property on type 'Conversation'

Finally I've found solution, stupid mistake. In Conservation it should be

    [ForeignKey("Sender"), Column(Order = 0)]

    public Guid SenderId { get; set; }

    [ForeignKey("Receiver"), Column(Order = 1)]

    public Guid ReceiverId { get; set; }

And not

[ForeignKey("SenderId"), Column(Order = 0)]
[ForeignKey("ReceiverId"), Column(Order = 1)]

After that I got error:

"Introducing FOREIGN KEY constraint 'FK_dbo.Conversations_dbo.Users_ReceiverId' on table 'Conversations' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint. See previous errors."

And solution is: in DbContext this code:

        modelBuilder.Entity<Conversation>()
           .HasRequired(s => s.Sender)
           .WithMany(s => s.ConversationSenders)
           .HasForeignKey(s => s.SenderId)
           .WillCascadeOnDelete(false);


        modelBuilder.Entity<Conversation>()
            .HasRequired(r => r.Receiver)
            .WithMany(r => r.ConversationReceivers)
            .HasForeignKey(r => r.ReceiverId)
            .WillCascadeOnDelete(false);

I've tested it and now everything works fine =)


[ForeignKey("SenderId")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid SenderId { get; set; }

[ForeignKey("RecieverId")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid RecieverId { get; set; }

these two line mistakenly marked with [DatabaseGenerated(DatabaseGeneratedOption.Identity)] attribute.remove these two attribute from properties.corrected version should be :

[ForeignKey("User")]    
public Guid SenderId { get; set; }

[ForeignKey("User")]   
public Guid RecieverId { get; set; }

Comments

  1. Andrew

    • 2017/2/26

    . Unlike other properties, navigation properties do not carry data. A navigation property definition includes the following: A name.

  2. Gideon

    • 2018/10/23

    A navigation property is an optional property on an entity type that allows for navigation from one end of an association to the other end. Unlike other properties, navigation properties do not carry data. A navigation property definition includes the following: A name. (Required) The association that it navigates. (Required)

  3. Cooper

    • 2018/12/29

    Every object can have a navigation property for every relationship in which it participates. Navigation properties allow you to navigate and 

  4. Michael

    • 2018/7/26

    These are the two ends of the expression of the navigation properties and it shows that the client can have multiple projects due to which, the project is defined in the collection inside the client. On the other hand, the project only links with the single client, due to which it contains the client type entity.

  5. Rome

    • 2017/11/9

    What is the Navigation Property? It is a way to represent a foreign key relationship in the database or define the relationship between the 

  6. Leone

    • 2018/7/21

    It is the property of an Entity that represents a link from the Entity to one or more related Entities. The Navigation Property is tied to an Association Type and allows the navigation from one end of the Entity Type that declares the Navigation Property, to the other related end. Navigation property is required to create a link from one entity to another via an association.

  7. Emiliano

    • 2016/11/10

    Each leg of the property path is represented by a navigation property. The Customer.Orders property travels from a customer to its collection of orders The 

  8. Frasheri

    • 2016/8/14

    What is a navigation property? Navigation properties are Entity Frameworks way of representing Foreign Key relationships inside the database. Navigation properties allow you to define relationships between entities (rows in your database) in a way that makes sense in an object oriented language. Consider the following database:

  9. Houston

    • 2019/10/24

    The Navigation Property folder displays only when an entity type is added. See Related Links for more information. Open the Service Builder. Expand the Data 

  10. Abazi

    • 2020/1/22

    Access the navigation prop from any component. useNavigation is a hook which gives access to the navigation object. It's useful when you cannot pass the navigation prop into the component directly, or don't want to pass it in case of a deeply nested child. An ordinary component that is not a screen component will not receive the navigation prop automatically.

  11. Cruz

    • 2021/7/16

    The navigation property represents a relationship to another entity. There are two types of navigation properties: Reference Navigation and Collection 

  12. Mack

    • 2016/11/24

    Are you worried about performance? A) No: if you are not then you shouldn't worry about this and always use navigation properties for 

  13. Mauricio

    • 2021/2/14

    Windchill REST Services reads the navigation property, which is a JSON array, from the <Entity JSON> file. Each entry in the navigations section defines one 

  14. Houston

    • 2015/9/28

    The InverseProperty attribute is used to denote the inverse navigation property of a relationship when the same type takes part in multiple relationships.

Comments are closed.

Recent Posts