0

I'm learning Entity Framework and decided to re-implement a knowledge base application which I had written using ADO.NET a few years back.

I have three entities: Article, UserAccount and Rating.

Article and UserAccount are pretty self-explanatory. Rating is a table containing possible ratings: very good = 5, good = 4, average = 3, poor = 2 and very poor = 1.

When viewing articles I want to display the average rating for that article. If a user has already providing a rating on that article - they shouldn't be allowed to rate on it again.

I've managed to successfully create Lookup tables between two entities using fluent API, using something similar to:

        HasMany(a => a.Tags)
            .WithMany(t => t.Articles)
            .Map(x =>
                {
                    x.ToTable("ArticleTags");
                    x.MapLeftKey("ArticleId");
                    x.MapRightKey("TagId");
                });

I am struggling to create or even attempt start creating the lookup table between three tables:

ArticleUserRatings (ArticleId, UserAccountId, RatingId)

I could create an entity called ArticleUserRating

public class ArticleUserRating
{
    public int ArticleId { get; set; }
    public int UserAccountId { get; set; }
    public int RatingId { get; set; }
}

but this doesn't sit comfortable with me, its a entity for the sake of this relationship type.

Is there a way to define this relationship without creating the entity?

Any guidance will be much appreciated.

4

0 回答 0