Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用SilverLight Linq到SQL从2个SQL表中删除_C#_Silverlight_Linq To Sql - Fatal编程技术网

C# 使用SilverLight Linq到SQL从2个SQL表中删除

C# 使用SilverLight Linq到SQL从2个SQL表中删除,c#,silverlight,linq-to-sql,C#,Silverlight,Linq To Sql,我在SQL中得到了两个表,它们都有一个名为Selection\u ID的字段。我想使用Linq to SQL删除所有带有Selection\u ID=inpSelectionID的行 我的桌子: 我的C#函数: void buttonDeleteSelectionList_Click(object sender, RoutedEventArgs e, Canvas canvasAdvancedSearchFieldResults, int inpSelectionID) { Posi

我在SQL中得到了两个表,它们都有一个名为Selection\u ID的字段。我想使用Linq to SQL删除所有带有
Selection\u ID=inpSelectionID
的行

我的桌子:

我的C#函数:

void buttonDeleteSelectionList_Click(object sender, RoutedEventArgs e, Canvas canvasAdvancedSearchFieldResults, int inpSelectionID)
{

    PositionServiceReference.PositionServiceClient service = new PositionServiceReference.PositionServiceClient();
    service.DeleteSelectionCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(service_DeleteSelectionCompleted);
    service.DeleteSelectionAsync(inpSelectionID);
}
[OperationContract]
void DeleteSelection(int inpSelectionID)
{
    PositionDataClassesDataContext context = new PositionDataClassesDataContext();

    context.Lloyds_Selection.DeleteOnSubmit(inpSelectionID);
    context.SubmitChanges();

    context.Lloyds_Selection_Vessels.DeleteOnSubmit(inpSelectionID);
    context.SubmitChanges();
}

deleteosubmit
需要实体对象作为参数,因此,如果不先从数据库中选择该项,则无法删除该项。还有
deleteAllonsSubmit
方法,但它也需要实体的
IEnumerable
。您可以这样使用它:

context.Lloyds_Selection.DeleteAllOnSubmit(context.Lloyds_Selection.Where(l => l.Selection_ID  == inpSelectionID));
但是,您可以使用
DataContext.ExecuteCommand
对数据库执行原始SQL:

string command = string.format("DELETE FROM Lloyds_Section WHERE Selection_ID = {0}", inpSelectionID");
context.ExecuteCommand(command );

谢谢正是我想要的;-)