Which is the opposite of.equals in C#?
I'm doing a left Join where I want to take only what has in the left table and does not have in the right one.
I'm using LINQ and EntityFramework. I made a code that takes the similarities, follows below:
var mQuery = from pessoa in clientes
from prod in produtos
on pessoa.grupo equals prod.grupo
Select New { pessoa.nome, prod.descricao }
Like I said, I'm training LINQ and Entity. I wanted a method that would necessarily do the opposite of equals. Note: the operator != did not work
Vlww
2 answers
You can use except
Except is the LINQ extension method that subtracts elements from a collection. For example, this will remove elements from the first entities (list1) that are elements in the second entities(list2) and that will be returned as a third entity (List3).
var Lista3 = Lista1.Except(Lista2);
Another more complete example:
int[] Lista1 = { 5, 3, 9, 7, 5, 9, 3, 7 };
int[] Lista2 = { 8, 3, 6, 4, 4, 9, 1, 0 };
int[] Lista3 = Lista1.Except(Lista2).ToArray();
Console.WriteLine("Resultado:");
foreach (int num in Lista3){
Console.WriteLine("{0} ", num);
}
Result: 7 and 5.
List1 : Select result complete.
List2 : Select with the data that should not appear.
List3 : result of method except, bringing only the different data from list2.
Note: this operator is as if it were a not in.
I found the answer I was looking for. There is no method that is opposite to .Equal. The name of what I was looking for was Outer left Join. The challenge was that I wanted to use only the LINQ framework.
Follows below:
var permissoesCliente = from permi in context.tabelaPermissoes
join aces in context.tabelaAcessos
on permi.CodigoPermissao equals
aces.CodigoPermissao into tt
from tabelaTemp in pp.DefaultIfEmpty()
where tabelaTemp == null
select new { permi.CodigoPermissao };