How to link non-primitive field (PK) with primitive key (FK) in EF Core via fluent API

Viewed 26

I have a table User which is modelled in C# as an entity with UserId as follows:

public class User : Entity<UserId>
{
    public UserId userId { get; private set; }
    ...
}

public class UserId : ValueObject
{
    public long DbId { get; private set; }
    ...
}

I have another class Role which has many users:

public class Role : Entity
{
    public List<long> Users { get; set; }
}

Is there any way to create a FK from type UserId to long?

I mapped it like this:

map.HasOne<User>()
   .WithMany()
   .HasForeignKey(x => x.UserId);
0 Answers
Related