maxime
maxime

Reputation: 1

EF core: Map Many to Many relationship without navigation property and on a none primary key

I have the entity:

public class UserQuestion
{
    public Guid UserId { get; set; }
    public bool HasCompletedQuestion { get; set; }
    public Guid? QuestionInformationSetId { get; set; }
    public DateTimeOffset CreatedAt { get; set; }

    public List<QuestionInformation> QuestionInformation { get; set; } = new();
}

and

public class QuestionInformation
{
    public Guid Id { get; set; }
    public string Title { get; set; }
    public string Text { get; set; }
    public int Order { get; set; }
    public Guid SetId { get; set; }
    public bool Archived { get; set; }
}

Is is possible to map a many to many relationship without having a navigation property on one of the ends and on the top of that base on a none primary key (base on QuestionInformationSetId and SetId)?

I have tried few solutions like:

builder.HasMany(i => i.QuestionInformation)
        .WithMany();
        .UsingEntity<Dictionary<string, object>>(
            "UserQuestionInformation",
            j => j.HasOne<QuestionInformationProjection>().WithMany().HasForeignKey("QuestionInformationSetId").HasPrincipalKey("SetId"));

unfortunately, ef core migration tries to add a join table to manage this type of relationship between UserQuestion and QuestionInformation

What i try to achieve is being able to navigate from UserQuestion to QuestionInformation without having a joint table and on a non primary key

Upvotes: 0

Views: 34

Answers (0)

Related Questions