LINQ - 如何翻译 patindex 和子字符串 [英] LINQ - How to translate patindex and substring

查看:32
本文介绍了LINQ - 如何翻译 patindex 和子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能帮我把这个 Transact-SQL 语句翻译成 LINQ 吗?

Could someone help me translate this Transact-SQL statement to LINQ?

select distinct SUBSTRING ( car# ,1 , PATINDEX ( '%[0123456789]%' , car# )-1 ) from dbo.Purchases

谢谢

推荐答案

如果您使用的是实体框架和 .NET 4.0,请查看 SqlFunctions 类.它包含常见内置 SQL 函数的定义(如 PatIndex) 可用于 LINQ to Entities 查询.在您的查询中使用时,这些函数会被翻译成相应的 SQL 函数.

If you're using Entity Framework and .NET 4.0, take a look at the SqlFunctions class. It contains definitions for common built-in SQL functions (like PatIndex) that can be used in your LINQ to Entities queries. When used in your queries, these functions are translated into the corresponding SQL function.

这篇关于LINQ - 如何翻译 patindex 和子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆