问题描述
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();
}
我有2表:工作流和WorkflowInstances
I have 2 tables: Workflows and WorkflowInstances.
工作流程来存储对象和workflowInstances存储实例
Workflows to store objects and workflowInstances to store instances.
工作流表:ID,名称,FirstStateID,LastStateID
Workflows Table: ID,Name,FirstStateID,LastStateID
WorkflowInstances表:ID,名称,WorkflowID,CurrentStateID
WorkflowInstances Table: ID,Name,WorkflowID,CurrentStateID
如何写在LINQ查询到SQL来选择从哪个CurrentStateID WorkflowInstances实例不等于LastStateID
How to write a query in linq to sql to select the instances from WorkflowInstances which CurrentStateID not equal LastStateID
推荐答案
您需要修改的连接要对两个表之间的相关列,那么你添加的条件WHERE子句中,像下面的:
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();
}
这篇关于如何写不等于运营商在LINQ to SQL的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!