I have an entity named User and a value object named UserRef containing UserId.
EF is picking up the UserId on the UserRef and trying to map it to a User.
This isn't intended as this entity is for DDD, and I have no interest in using it as a navigational property.
If I rename the UserRef property to User_Id, everything works fine.
How can I tell EF to leave the property alone, and stop trying to do anything with it (other than read/write its value)?
public class User
{
public Guid Id { get; private set; }
public UserRef? ArchivedByUser { get; private set; }
}
public class UserRef
{
public Guid UserId { get; private set; }
}
public class UserConfiguration : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder.HasKey(o => o.Id);
builder.OwnsOne(o => o.ArchivedByUser, archivedByUser => {
archivedByUser.Property(userRef => userRef.UserId)
.HasColumnName("ArchivedByUser");
});
}
}
I get the following error:
The keys {'UserId'} on 'User.ArchivedByUser#UserRef' and {'Id'} on 'User' are both mapped to 'User.PK_User' but with different columns ({'ArchivedByUser'} and {'Id'}).
Thanks!