I'm trying to map 2 properties of the same type in entity and getting this error:
An exception was thrown while executing a resolve operation. See the InnerException for details. ---> Introducing FOREIGN KEY constraint 'FK_dbo.Client_dbo.Messagebox_OutboxId' on table 'Client' 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. (See inner exception for details.)
I understand that this error related to the fact I'm having 2 props of the same type.
How can it done using code first + EF fluent API?
The scenario:
Each Client
has Inbox
and Outbox
which both are Messagebox
public class BaseEntity
{
public int Id { get; set; }
}
public class Client : BaseEntity
{
/// <summary>
/// Gets or sets Client Alias
/// </summary>
public string Alias { get; set; }
/// <summary>
/// Gets or sets value indicating if the client was deleted
/// </summary>
public bool Deleted { get; set; }
/// <summary>
/// Gets or sets client's inbox
/// </summary>
public virtual Messagebox Inbox { get; set; }
/// <summary>
/// Gets or sets inbox Id
/// </summary>
public int InboxId { get; set; }
/// <summary>
/// Gets or sets client's outbox
/// </summary>
public virtual Messagebox Outbox { get; set; }
/// <summary>
/// Gets or sets outbox Id
/// </summary>
public int OutboxId { get; set; }
}
public class Messagebox : BaseEntity
{
public int ClientId { get; set; }
/// <summary>
/// Gets or sets the messagebox client
/// </summary>
public virtual Client Client { get; set; }
}