Quando provo a fare Update-Database, ottengo questo errore:La struttura di navigazione 'SenderId' non è una proprietà dichiarata del tipo 'conversazione'
The navigation property 'SenderId' is not a declared property on type 'Conversation'. Verify that it has not been explicitly excluded from the model and that it is a valid navigation property.
Modifica
Credo problema è nella mappatura delle relazioni tra conversazione e utente, perché conversazione e utente sono connessi con due uno a molti rapporti cioè Conversazione ha due chiavi esterne che puntano a Utente
Ecco come Utente e conversazione sono connessi:
utente:
public class User
{
[Key]
[HiddenInput(DisplayValue = false)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid UserId { get; set; }
public virtual ICollection<Conversation> ConversationSenders { get; set; }
public virtual ICollection<Conversation> ConversationRecievers { get; set; }
Conversazione:
public class Conversation
{
[Key]
[HiddenInput(DisplayValue = false)]
public Guid ConversationId { get; set; }
[ForeignKey("SenderId")]
public Guid SenderId { get; set; }
[ForeignKey("RecieverId")]
public Guid RecieverId { get; set; }
[InverseProperty("ConversationSenders")]
public virtual User Sender { get; set; }
[InverseProperty("ConversationRecievers")]
public virtual User Reciever { get; set; }
}
Ecco il codice intero:
utente:
public class User
{
[Key]
[HiddenInput(DisplayValue = false)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid UserId { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid CollegeId { get; set; }
public int RoleId { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Surname { get; set; }
public string Gender { get; set; }
//role
public DateTime? DateOfBirth { get; set; }
public string ImageURL { get; set; }
[ForeignKey("CollegeId")]
public virtual College College { get; set; }
[ForeignKey("RoleId")]
public virtual UserRole UserRole { get; set; }
public virtual ICollection<Advert> Adverts { get; set; }
public virtual ICollection<Competition> Competitions { get; set; }
public virtual ICollection<Message> Messages { get; set; }
public virtual ICollection<Conversation> ConversationSenders { get; set; }
public virtual ICollection<Conversation> ConversationRecievers { get; set; }
public virtual ICollection<UserOS> UserOses { get; set; }
Conversazione:
public class Conversation
{
[Key]
[HiddenInput(DisplayValue = false)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid ConversationId { get; set; }
[ForeignKey("SenderId")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid SenderId { get; set; }
[ForeignKey("RecieverId")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid RecieverId { get; set; }
[InverseProperty("ConversationSenders")]
public virtual User Sender { get; set; }
[InverseProperty("ConversationRecievers")]
public virtual User Reciever { get; set; }
public virtual ICollection<Message> Messages { get; set; }
}
Messaggio
public class Message
{
[Key]
[HiddenInput(DisplayValue = false)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid MessageId { get; set; }
[HiddenInput(DisplayValue = false)]
public Guid UserId { get; set; }
[HiddenInput(DisplayValue = false)]
public Guid ConversationId { get; set; }
public string Text { get; set; }
public bool? IsSeen { get; set; }
[ForeignKey("UserId")]
public virtual User ConversationSender { get; set; }
[ForeignKey("ConversationId")]
public virtual Conversation Conversation { get; set; }
}
li ho rimossi, ma ancora lo stesso errore – hyperN
Puoi pubblicare il codice per il mittente e Ricevitore pure? –
@ Behnam Esmaili Sender e Receiver sono in realtà User, ci sono due connessioni da 1 a molte da Conversation a User, puoi cercarle nel codice, ma qui troverò quella parte esatta, quindi sarò più facile leggi il codice: Utente 'public virtual ICollection ConversationSenders {get; impostato; } pubblico virtuale ICollection ConversazioneRecievers {get; impostato; } ' –
hyperN