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 875577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:17:35+00:00 2026-05-15T11:17:35+00:00

I am using Entity Framework 4.0 and trying to use the Contains function of

  • 0

I am using Entity Framework 4.0 and trying to use the “Contains” function of one the object sets in my context object. to do so i coded a Comparer class:

    public class RatingInfoComparer : IEqualityComparer<RatingInfo>
    {           
        public bool Equals(RatingInfo x, RatingInfo y)
        {
            var a = new {x.PlugInID,x.RatingInfoUserIP};
            var b = new {y.PlugInID,y.RatingInfoUserIP};

            if(a.PlugInID == b.PlugInID && a.RatingInfoUserIP.Equals(b.RatingInfoUserIP))
                return true;
            else
                return false;
        }

        public int GetHashCode(RatingInfo obj)
        {
            var a = new { obj.PlugInID, obj.RatingInfoUserIP };

            if (Object.ReferenceEquals(obj, null))
                return 0;
            return a.GetHashCode(); 
        }


    }

when i try to use the comparer with this code:

    public void SaveRatingInfo2(int plugInId, string userInfo)
    {

        RatingInfo ri = new RatingInfo()
        {
            PlugInID = plugInId,
            RatingInfoUser = userInfo,
            RatingInfoUserIP = "192.168.1.100"
        };

        //This is where i get the execption
        if (!context.RatingInfoes.Contains<RatingInfo>(ri, new RatingInfoComparer()))
        {
            //my Entity Framework context object
            context.RatingInfoes.AddObject(ri);
            context.SaveChanges();
        }
    }

i get an execption:

“LINQ to Entities does not recognize the method ‘Boolean Contains[RatingInfo](System.Linq.IQueryable1[OlafCMSLibrary.Models.RatingInfo], OlafCMSLibrary.Models.RatingInfo,
System.Collections.Generic.IEqualityComparer
1[OlafCMSLibrary.Models.RatingInfo])’ method, and his method cannot be translated into a store expression.”

Since i am not proficient with linQ and Entity Framework i might be making a mistake with my use of the “var” either in the “GetHashCode” function or in general.

If my mistake is clear to you do tell me 🙂 it does not stop my project! but it is essential for me to understand why a simple comparer doesnt work.

Thanks
Aaron

  • 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-05-15T11:17:36+00:00Added an answer on May 15, 2026 at 11:17 am

    LINQ to Entities works by converting an expression tree into queries against an object model through the IQueryable interface. This means than you can only put things into the expression tree which LINQ to Entities understands.

    It doesn’t understand the Contains method you are using, so it throws the exception you see. Here is a list of methods which it understands.

    Under the Set Methods section header, it lists Contains using an item as supported, but it lists Contains with an IEqualityComparer as not supported. This is presumably because it would have to be able to work out how to convert your IEqualityComparer into a query against the object model, which would be difficult. You might be able to do what you want using multiple Where clauses, see which ones are supported further up the document.

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

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer $(".selector").validate({ onkeyup: true }) May 16, 2026 at 5:56 pm
  • Editorial Team
    Editorial Team added an answer I always use helper objects in that case: def outerFunction():… May 16, 2026 at 5:56 pm
  • Editorial Team
    Editorial Team added an answer Hmmm, I think I would approach this a different way.… May 16, 2026 at 5:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am trying use MySql and Entity Framework, using Connector/Net 6.1 with this as
I'm trying to understand some fundamental best practices using Entity Framework. My EDM design
I use a SQLite database and Entity Framework (with .net framework 3.5). I'm trying
I'm trying to use the repository pattern to save an entity using the Entity
I'm trying to get started using the latest Entity Framework 4 release on Visual
I am developing a medium sized ASP.NET project using ASP.NET MVC and Entity Framework.
Are there any open-source examples of ASP.NET MVC applications that use the Entity Framework?
I have just started Entity Framework & linq and write this query var query
I'm working on a .NET 4 application, C#, Entity Framework 4, SQL Server 2008.
I have a SampleDB that contains 3 tables. Table Employees (EmployeeID, EmployeeName) Table Projects

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.