我尝试将 SQL 删除命令更改为 LINQ。这是我的 SQL 命令:
DELETE FROM [TrackPoints]
WHERE [RouteFK] IN (SELECT RouteId
FROM Routes
WHERE UserId = @UserId)
这是我编写的 LINQ 代码:
int UID =1;
FirstDataContext aspnetdb = new FirstDataContext();
var res1 = from q1 in aspnetdb.Routes
where q1.UserId == UID
select q1.RouteId;
foreach (var k in res1)
{
var eigen = from p in aspnetdb.Trackpoints
where p.RouteFK == k
select p.TrackPointId;
aspnetdb.Trackpoints.DeleteOnSubmit(eigen.First());
aspnetdb.SubmitChanges();
}
但在这一行我有一个错误:
aspnetdb.Trackpoints.DeleteOnSubmit(eigen.First());
那说:
'System.Data.Linq.Table.DeleteOnSubmit(LINQ_Test.Trackpoint)' 的最佳重载方法匹配有一些无效参数
我该怎么办?