score:2
It compares the values .
Also see Linq: What is the difference between == and equals in a join?
score:1
That depends on the object. If it's a value type, usually the vaules are compared, it it's a reference type, the references are compared, unless the Equals() method is overridden.
From MSDN:
The default implementation of Equals supports reference equality for reference types, and bitwise equality for value types. Reference equality means the object references that are compared refer to the same object. Bitwise equality means the objects that are compared have the same binary representation.
Note that a derived type might override the Equals method to implement value equality.
score:0
The ‘equals’ within a join query uses the default equality comparer to compare keys using a keyed lookup. The join is implemented in Enumerable.Join and the key can be either a value or a reference. When querying using Linq to Sql the key is usually a value as primary keys normally map to value types. However as the following code illustrates the equals comparison can be either by value or by reference which ever is appropriate for the key type:
KeyObj k1 = new KeyObj(); k1.Id = 1001;
KeyObj k2 = new KeyObj(); k2.Id = 1002;
KeyObj k3 = new KeyObj(); k3.Id = 1003;
KeyObj k4 = new KeyObj(); k4.Id = 1004;
KeyObj k5 = new KeyObj(); k4.Id = 1005;
List<Foo> foos =
new List<Foo>()
{
new Foo("o1",k1),
new Foo("o2",k2),
new Foo("o4",k5)
};
List<Bar> bars =
new List<Bar>()
{
new Bar("o2",k1),
new Bar("o3",k2),
new Bar("o4",k4),
new Bar("o5",k5)
};
var foobar = from f in foos
join b in bars on f.Ko equals b.Ko
select f.Name + " in foos joined by reference with " + b.Name + " in bars ";
foreach (var v in foobar)
{
Debug.WriteLine(v);
}
foobar = from f in foos
join b in bars on f.Name equals b.Name
select f.Name + " in foos joined by value with " + b.Name + " in bars ";
foreach (var v in foobar)
{
Debug.WriteLine(v);
}
class KeyObj { public int Id { get; set; } }
class Foo : Base
{
public Foo(string s, KeyObj ko) : base(s, ko) { }
}
class Bar : Base
{
public Bar(string s, KeyObj ko) : base(s, ko) { }
}
class Base
{
string _name = "";
public string Name { get { return _name; }}
KeyObj _ko = null;
public KeyObj Ko { get { return _ko; }}
public Base(string s, KeyObj ko)
{
_name = s;
_ko = ko;
}
}
The output from this is:
o1 in foos joined by reference with o2 in bars
o2 in foos joined by reference with o3 in bars
o4 in foos joined by reference with o5 in bars
o2 in foos joined by value with o2 in bars
o4 in foos joined by value with o4 in bars
score:0
From MSDN: http://msdn.microsoft.com/en-us/library/bb311040.aspx
The equals operator
A join clause performs an equijoin. In other words, you can only base matches on the equality of two keys. Other types of comparisons such as "greater than" or "not equals" are not supported. To make clear that all joins are equijoins, the join clause uses the equals keyword instead of the == operator. The equals keyword can only be used in a join clause and it differs from the == operator in one important way. With equals, the left key consumes the outer source sequence, and the right key consumes the inner source. The outer source is only in scope on the left side of equals and the inner source sequence is only in scope on the right side.
Source: stackoverflow.com
Related Articles
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- LINQ Source Code Available
- using the equals keyword in linq
- creating Linq to sqlite dbml from DbLinq source code
- source code for LINQ 101 samples
- c# Linq or code to extract groups from a single list of source data
- Convert string[] to int[] in one line of code using LINQ
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- Linq 'into' keyword confusion
- Creating a LINQ Expression where parameter equals object
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- LINQ 'join' expects an equals but I would like to use 'contains'
- Syntax to execute code block inside Linq query?
- linq remove item from object array where property equals value
- Query data using "Contains" keyword in Dynamic Linq in C#
- Linq join without equals
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Best open source LINQ provider
- Is there a good source that gives an overview of linq optimizations?
- Does this LINQ code perform multiple lookups on the original data?
- When to prefer joins expressed with SelectMany() over joins expressed with the join keyword in Linq
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ Union not going into overridden Equals method
- Using Linq not equals
- Linq How to Get Average When all values equals null or 0 ? MVC
- LINQ WHERE method alters source collection
- What is LINQ equivalent of SQL’s "IN" keyword
- Linq distinct doesn't call Equals method
- Linq to Xml: selecting elements if an attribute value equals a node value in an IEnumerable<XElement>
- Join multiple lists and get output as comma separated string
- handling null byte array values in a LINQ query
- What would be the best way to get all the products in all the child categories of a selected main category?
- IEnumerable<SelectListItem> in C# mvc
- Order By String which matches property name gives Null Reference
- cosmosdb where clause in sub lists with linq
- Cast method of LINQ behaves unexpected
- Timeout exception running Linq Statement
- Sort List of SelectListItem with LINQ
- How to split below C# lambda expression into separate methods?
- Sort specific values inside a list through LINQ
- remove duplicate from ObservableCollection<T>
- How can I implement select case in Entity Framework?
- How to use LINQ to combine two or more collections into one collection
- How to map multiple entities from LINQ query into a new entity using a common map method
- Select statement only searches by check boxes when kept in the where statement
- multiple Orderby and Sort
- selecting date where date can be null
- Show year only from datetime using C# Dropdownlist and LINQ
- How to concat only unique columns with data