2016-03-16 2 views
1

Я очень не понимаю, почему это не работает, похоже, работает только на прошлой неделе, и я не вижу никаких изменений в этих классах. Может кто-то пожалуйста, дайте мне знать, почему я получаю сообщение об ошибке:EF: свойство навигации не является объявленным свойством по типу

"The navigation property 'Node' is not a declared property on type 'NWatchRelation'. Verify that it has not been explicitly excluded from the model and that it is a valid navigation property."

NWatchRelation Entity

public class NWatchRelation : INWatchRelation 
    { 
     private NWatchRelation() 
     { 
     } 

     public NWatchRelation(int nodeId, int relatedNodeId) 
     { 
      NodeId = nodeId; 
      RelatedNodeId = relatedNodeId; 
     } 

     public NWatchRelation(NWatchNode node, NWatchNode relatedNode) 
     { 
      Node = node; 
      RelatedNode = relatedNode; 
     } 

     public int Id { get; set; } 

     /// <summary> 
     /// Foreign Key for Node 
     /// </summary> 
     public int NodeId { get; set; } 

     /// <summary> 
     /// Node 
     /// </summary> 
     public NWatchNode Node { get; set; } 

     /// <summary> 
     /// Foreign Key for RelatedNode 
     /// </summary> 
     public int RelatedNodeId { get; set; } 

     /// <summary> 
     /// Related Node 
     /// </summary> 
     public NWatchNode RelatedNode { get; set; } 

     /// <summary> 
     /// Relationship Type 
     /// </summary> 
     public NWatch.NWatchRelationType RelationType { get; set; } 

     INWatchNode INWatchRelation.Node 
     { 
      get 
      { 
       return Node; 
      } 
     } 

     INWatchNode INWatchRelation.RelatedNode 
     { 
      get 
      { 
       return RelatedNode; 
      } 
     } 
    } 

Конфигурация

// NWatchRelation 
      modelBuilder.Entity<NWatchRelation>().Map(m => 
      { 
       m.ToTable("NWatchRelations"); 
      }); 
      modelBuilder.Entity<NWatchRelation>() 
       .HasKey(t => t.Id) 
       .Property(t => t.Id) 
       .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); 
      modelBuilder.Entity<NWatchRelation>().HasRequired(t => t.Node). 
       WithMany().HasForeignKey(t => t.NodeId).WillCascadeOnDelete(false); 
      modelBuilder.Entity<NWatchRelation>().HasRequired(t => t.RelatedNode). 
       WithMany().HasForeignKey(t => t.RelatedNodeId).WillCascadeOnDelete(false); 

ответ

2

Я думаю, вы должны указать атрибут внешнего ключа если вы считаете это навигационным свойством

[ForeignKey("Node"), Column(Order = 0)] 
public int NodeId { get; set; } 
Смежные вопросы