【问题标题】:SQL Query to Linq To EntitiesSQL 查询到 Linq To 实体
【发布时间】:2013-05-16 16:10:34
【问题描述】:

我正在使用 Linq To Entities,但很难将 SQL 查询转换为 Linq。

这是我在 SQL 中的查询:

SELECT row FROM table
WHERE row not between 'A' and 'Z' 
and NOT REGEXP_LIKE(row,'[[:digit:]]{3}')

实际上我的行是一个 varchar,我希望查询返回不是单个大写字母或 3 个字符数字(仅“A”或“123”)的项目。

【问题讨论】:

    标签: sql linq entity-framework


    【解决方案1】:
    from row in table
    where !RegEx.Match(row, "^([A-Z]|[0-9]{3})$").Success
    select row
    

    【讨论】:

    • Linq To 实体不支持正则表达式。但是,如果我将查询转换为 IEnumerable 如下所示: var query = from item in Db.Table.AsEnumerable() where !Regex.Match(item.row, "^([A-Z]|[0-9 {3} )$").Success select item.row;我找到了另一种解决方案而无需转换为 IEnumerable 但它要长得多。
    • 抱歉,不知道 LinqToEntities 中的非正则表达式支持。我对 Linq 很了解,但对 LinqToEntities 知之甚少。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    相关资源
    最近更新 更多