Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:37:23+00:00 2026-06-13T18:37:23+00:00

This is probably just some simple beginner’s mistake, but I just can’t seem to

  • 0

This is probably just some simple beginner’s mistake, but I just can’t seem to figure it out.

I’m just trying to get started with entity framework (ef 5.0, .net 4.5), been rolling all my own sql statements until now. I’m trying to work with an existing database and EF code first, with two simple classes that have a one to many relationship: clips and clip_ratings (there can be zero or many ratings for each clip). the relevant parts of the classes are:

public class clip
{
    public clip()
    {
        this.Ratings = new List<clip_ratings>();
    }

    public virtual ICollection<clip_ratings> Ratings { get; set; }

    public int clip_id { get; set; }
    public Nullable<int> clip_type { get; set; }
    // ...
 }

public class clip_ratings
{
    public int cr_id { get; set; }
    public int cr_clip_id { get; set; }
    // ...

    [ForeignKey("cr_clip_id")]
    public clip Clip { get; set; }
}

Now I’m trying to read some data from the DB:

           var query = from b in db.clips
                        orderby b.clip_id where b.Ratings.Count > 1
                        select b;

            foreach (var item in query)
            {
                Console.WriteLine(item.Ratings.Count +" | "+item.clip_linktext);
            }

The query returns the correct resultset from the DB, however it errors on the item.Ratings.Count. When I just output item.clip_linktext all is fine, but with the item.Ratings.Count I get the following error:

More than one item in the metadata collection match the identity ‘clip_ratings’.

I’ve tried following all the MS EF tutorials and reading up on some more posts, but just can’t seem to figure it out. Hope somebody here can help me along on this (and that it is easy to fix ;))

update: adding the classMap.cs sources:

public class clipMap : EntityTypeConfiguration<clip>
{
    public clipMap()
    {
        // Primary Key
        this.HasKey(t => t.clip_id);
        // ...


        // Table & Column Mappings
        this.ToTable("clips");
        this.Property(t => t.clip_id).HasColumnName("clip_id");
        this.Property(t => t.clip_type).HasColumnName("clip_type");
        ...
     }
 }

public class clip_ratingsMap : EntityTypeConfiguration<clip_ratings>
{
    public clip_ratingsMap()
    {
        // Primary Key
        this.HasKey(t => t.cr_id);
        // Table & Column Mappings
        this.ToTable("clip_ratings");
        this.Property(t => t.cr_id).HasColumnName("cr_id");
        this.Property(t => t.cr_clip_id).HasColumnName("cr_clip_id");
        // ...
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:37:24+00:00Added an answer on June 13, 2026 at 6:37 pm

    ok, after another hour of messing with about every part of this simple example I found a solution: apparently EF didn’t like the collection being called “Ratings”, even though there’s no part in the DB or code anywhere with a property/field/attribute of that name.

    Changed the name to Votes instead of Ratings to

        public clip()
        {
            this.Votes = new List<clip_ratings>();
        }
    
        public virtual ICollection<clip_ratings> Votes { get; set; }
    

    and everything works just fine.

    Guess that’s why I’ve avoided these kind of frameworks so far, you never really know what they’re doing under the hood 😉

    And yes, if I get a chance to remodel the db, I will try to follow the naming conventions.

    If anyone has a good explanation of why it didn’t work with Ratings, I’d still like to hear it, to be able to avoid similar situations in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Probably some simple derp but I just can't figure this out, I'm using almost
This is probably something really simple but for some reason I just can't seem
This is probably some simple mistake, I just can't seem to find it in
This is probably going to be a really simple fix... I just can't figure
Very simple problem, but can't seem to solve it. I'm probably just not thinking
This will probably be just another unsolved thread but i'll fill in some info
This is probably quite simple, but I just don't know how to do this...
This is probably simple for some of you, but I'm having trouble with it.
This is probably a simple question but I am stumped and just don't know
This is probably just me being stupid somehow or the other, but I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.