如果我的问题看起来很愚蠢,请原谅我,但我对 Workflow 完全陌生。我想做的是:我在 Workflow Foundation 项目中有一些数据库命中,在 ASP.NET 应用程序中有一些命中。我想要实现的是在同一个事务中在 Workflow Foundation 和 ASP.NET 中执行数据库操作。告诉我可能吗?我正在使用 linq2sql。
这是我的代码:
using(var context = new MyDBContext())
{
context.Transaction = context.Connection.BeginTransaction();
//Here I am calling my Workflow function
using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
waitHandle.Set();
if ((string)e.OutputParameters["OutputMessage"] != "")
msg = "Workflow error : " + (string)e.OutputParameters["OutputMessage"];
};
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
Console.WriteLine("ERROR: " + e.Exception.Message);
waitHandle.Set();
};
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(MyWorkflow), parameters);
instance.Start();
waitHandle.WaitOne();
}
//DB Operation in ASP.NET
context.DbOperation();
context.SubmitChanges();
context.Transaction.Commit();
}