用户登录
还没有账号?立即注册
用户注册
点击换图
投稿取消
文章分类:
还能输入300字

上传中....

热门文章更多>>
标签更多>>
专题更多>>
最新文章更多>>

如何在 linq to sql 中编写不等于运算符?

using (RapidWorkflowDataContext context = new RapidWorkflowDataContext()){var query = from w in context.WorkflowInstances在 w.WorkflowID 上的 context.Workflows 中加入 c 等于 c.ID其中 EmpWorkflowIDs.Contains((int)w.ID)&&w.CurrentStateID != c.LastStateID选择 w;返回 query.ToList();}

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

解决方案

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();
                        }