'Unable to determine the relationship represented by navigation 'UserAddress.CreatedBy
I get the error on the title when trying to run a query in the Context.
The related entities are as follow:
public abstract class Entity : IEntity
{
public abstract Guid Id { get; set; }
public DateTime DateCreated { get; set; }
public DateTime? DateDeleted { get; set; }
public DateTime LastModified { get; set; }
[ForeignKey("CreatedById")]
public virtual User CreatedBy { get; set; }
[ForeignKey("LastModifiedById")]
public virtual User LastModifiedBy { get; set; }
[ForeignKey("DeletedById")]
public virtual User DeletedBy { get; set; }
public Guid? CreatedById { get; set; }
public Guid? LastModifiedById { get; set; }
public Guid? DeletedById { get; set; }
}
public class User : Entity
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public override Guid Id { get; set; }
[MaxLength(255)]
public string Alias { get; set; }
[MaxLength(255)]
public string WindowsUserName { get; set; }
[NotMapped]
public byte VersionMajor { get; set; } = 0;
[NotMapped]
public byte VersionMinor { get; set; } = 0;
public DateTime? LastAccess { get; set; }
public string LastIP { get; set; }
public byte AvailableRestorations { get; set; }
public byte AuthForms { get; set; }
public DateTime? DeathDate { get; set; }
public DateTime? LastDownloaderCheck { get; set; }
public DateTime? LastUpdate { get; set; }
#region NProps
public virtual ICollection<UserAddress> UserAddresses { get; set; }
#endregion
}
public class UserAddress : Entity
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public override Guid Id { get; set; }
[MaxLength(6)]
public byte[] MacAddress { get; set; }
public string IP { get; set; }
public DateTime? LastUse { get; set; }
#region NProps
[ForeignKey("UserId")]
public virtual User User { get; set; }
#endregion
#region FKs
public virtual Guid UserId { get; set; }
#endregion
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserAddress>()
.HasOne(e => e.User)
.WithMany(e => e.UserAddresses)
.HasForeignKey(e => e.UserId);
}
All my entities inherit from the abstract Entity class.
This was working normally with Entity Framework 6. As I upgraded to EF-Core 6.0.2, I have throws from queries.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
