What's the difference between using "equals" vs == in LINQ to Entities?

2

As I mentioned above, when I say equals of LINQ to Entities I'm referring specifically to the C # reserved word and not to Equals() of System.Object .

Source: equals (C # Reference)

The following example returns all red products.

String color = "Red";
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
    var query =
        from product in context.Products
        where product.Color == color
        select new
        {
            Name = product.Name,
            ProductNumber = product.ProductNumber,
            ListPrice = product.ListPrice
        };

    foreach (var product in query)
    {
        Console.WriteLine("Name: {0}", product.Name);
        Console.WriteLine("Product number: {0}", product.ProductNumber);
        Console.WriteLine("List price: ${0}", product.ListPrice);
        Console.WriteLine("");
    }
}

Source: Query expression syntax examples: filtering | Microsoft Docs

Doubt: What is the difference or impact when changing == to equals ? When doing this change is the select mounted in the same way?

Note: I'm not referring to the .Equals() method

    
asked by anonymous 06.12.2018 / 23:34

1 answer

2

You can not use equals , it would give error because equals is a join clause that you are not using.

In a join you use to make the connection between two sequences of data using the field of one of them against the field of the other, in this way it is clear that this is not a comparison of pure and simple equality that would return a Boolean as a result, is a different mechanism.

    
06.12.2018 / 23:55