c# - Linq 查询删除包含特定匹配号码的所有数据

标签 c# linq

我的数据库中保存了包含 pointNumber 字段的数据,该字段是 int

我有一个剑道网格,当我单击“删除”按钮时,我希望能够删除数据库中 pointNumberpointNumber 匹配的行> 那一行。

到目前为止,我正在尝试这样的事情:

public ActionResult Delete(PlanningViewParam data)
{
    List<PointData> Points = UserSession.GetValue(
        StateNameEnum.Planning, 
        ScreenName.Planning.ToString() + "Points" + data.ViewType,
        UserSessionMode.Database) as List<PointData>;

    int Number = 1;
    Number = data.Number;

    PointData point = Points.Where( a=> a.pointNumber == Number);
    if (point != null)
    {
       Points.Remove(point);
    }
}

我坚持的部分是这个 LINQ 查询:

PointData point = Points.Where(a => a.pointNumber == Number);

我收到这个错误:

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'PointData'. An explicit conversion exists (are you missing a cast)?

这是什么意思,我该如何调整我的查询?

最佳答案

您可以进行的一项调整是:

Points.RemoveAll( a=> a.pointNumber == Number);

这样您就不必获取 Where 的结果并对其进行操作。

关于c# - Linq 查询删除包含特定匹配号码的所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29680943/

相关文章:

c# - 如何使用 SpecFlow 测试选择的 html 控件对象?

c# - DllNotFoundException : TMPro_Plugin, 在 Linux 上使用 TextMesh Pro

C# 通用条件 where 子句

c# - StackExchange.Redis:没有可用的连接服务此操作。无法在HOST:PORT上连接/交互

c# - LINQ 交叉连接列表列表?未知数量列表的笛卡尔积

c# - 解决linq表达式错误

c# - 警告 : No element in the source document matches '/configuration/connectionStrings/add[@name=' MyDB']'

c# - 搜索字符串列表以仅返回与 Linq 中的另一个输入字符串列表匹配的字符串

c# - 使用 LINQ 查找通用组件

c# - 在动态 linq 查询中使用变量