I have two entities:
class User
{
public Guid UserId { get; set; }
}
class ActionLog
{
public Guid ActionLogId { get; set; }
public Guid UserId { get; set; }
public User User {get; set;}
}
When I add those to EF Core data context a foreign key is generated by convention on ActionLog.UserId, but I would like just to log UserId without a relation. I don't want cascade deletes and key checks. How could I remove that convention?
This code removes foreign key relation with User as well as keeps UserId column without relation attached to User. Tested with ef core 6.
modelBuilder.Entity<ActionLog>().Ignore(e => e.User);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With