Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write not equal operator in linq to sql?

using (RapidWorkflowDataContext context = new RapidWorkflowDataContext())
                    {
                        var query = from w in context.WorkflowInstances
                        from c in context.Workflows 
                         where EmpWorkflowIDs.Contains((int)w.ID) && w.CurrentStateID != c.LastStateID
                         select w;

                        return query.ToList();
                    }

I have 2 tables: Workflows and WorkflowInstances.

Workflows to store objects and workflowInstances to store instances.

Workflows Table: ID,Name,FirstStateID,LastStateID

WorkflowInstances Table: ID,Name,WorkflowID,CurrentStateID

How to write a query in linq to sql to select the instances from WorkflowInstances which CurrentStateID not equal LastStateID

like image 369
Anas Salem Avatar asked Aug 16 '13 13:08

Anas Salem


People also ask

What is the LINQ equivalent to the SQL IN operator?

Perform the equivalent of an SQL IN with IEnumerable. Contains().

How do you write not equal condition in LINQ?

Linq not equal(!=)

What is the use of except in LINQ?

In LINQ, the Except method or operator is used to return only the elements from the first collection, which are not present in the second collection.


1 Answers

If you are using lambda expressions, then not(!) goes there:

.Where(p => !p.Whatever...)
like image 177
renakre Avatar answered Sep 24 '22 20:09

renakre