Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

c# - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to revise the join to be on the related columns between the 2 tables, then you add your condition in the where clause, like the following:

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

                            return query.ToList();
                        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...