像实体框架中的运营商? [英] Like Operator in Entity Framework?

查看:86
本文介绍了像实体框架中的运营商?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们试图在实体框架中为实体使用字符串字段来实现LIKE运算符,但它似乎不被支持。有没有人试图做这样的事情?

We're trying to implement the "LIKE" operator in Entity Framework for our entities with string fields, but it doesn't appear to be supported. Has anyone else tried to do something like this?

这个博客总结了我们所遇到的问题。我们可以使用包含,但只匹配最简单的例子。结合contains,startswith,endswith和indexof可以让我们在那里,但需要在标准通配符和Linq to Entities代码之间进行转换。

This blog post summarizes the issue we're having. We could use contains, but that only matches the most trivial case for LIKE. Combining contains, startswith, endswith, and indexof gets us there, but requires a translation between standard wildcards and Linq to Entities code.

推荐答案

这是一个旧帖子,但是对于任何人来说,这个链接应该有帮助:

This is an old post now, but for anyone looking for the answer, this link should help:

http://msdn.microsoft.com/en-us/library/system.data.objects.sqlclient.sqlfunctions.patindex。 aspx

SqlFunctions.PatIndex方法 - 返回指定表达式中第一次出现模式的起始位置,或零如果没有找到模式,在所有有效的文本和字符数据类型上

SqlFunctions.PatIndex Method - Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types

命名空间:System.Data.Objects.SqlClient
装配:System.Data.Entity (在System.Data.Entity.dll中)

Namespace: System.Data.Objects.SqlClient Assembly: System.Data.Entity (in System.Data.Entity.dll)

此论坛主题中有一点解释:

A bit of an explanation appears in this forum thread:

http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/5ede2db0-a4f9 -4178-84c0-fabf4d3a57fa

这篇关于像实体框架中的运营商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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