When you perform a union in linq to sql, will it be by reference - if the reference to the object point to the same object - or is it by the id field?
Example method:
public IEnumerable<CustomerModel> GetCustomers(string searchCriteria)
{
ExpressLogger.LogDebug("Enter");
try
{
var datacontext = Helpers.Utils.GetCustomerRmhDataContext();
using(datacontext)
{
var accountCustomers = datacontext.Customers.Where(c =>
c.AccountNumber.ToLower().Contains(searchCriteria.ToLower())).Select(c=>convertRmhToModel(c,datacontext)).ToList();
var phoneCustomers = datacontext.Customers.Where(c =>
c.PhoneNumber.ToLower().Contains(searchCriteria.ToLower())).Select(c => convertRmhToModel(c, datacontext)).ToList();
var personalNumberCustomers = datacontext.Customers.Where(c =>
c.TaxNumber.ToLower().Contains(searchCriteria.ToLower())).Select(c => convertRmhToModel(c, datacontext)).ToList();
var emailCustomers = datacontext.Customers.Where(c =>
c.EmailAddress.ToLower().Contains(searchCriteria.ToLower())).Select(c => convertRmhToModel(c, datacontext)).ToList();
var allCustomers = accountCustomers.Union(phoneCustomers).Union(personalNumberCustomers).Union(emailCustomers).ToList();
return allCustomers;
}
}
catch (Exception ex)
{
ExpressLogger.LogError(ex.Message);
throw;
}
}
This function do what i want, it searches for customer for accountnumber, phone, mail and swedish personalnumber. And then i make a union and return the result. But im curios - how does this work, will it compare the union with the ID field or is it by reference - will it check hashcode and equal comparer? (is it the same for intersect and except?)