像运营商在实体框架?运营商、实体、框架

2023-09-02 21:08:00 作者:暮色挽歌

我们正在努力实现实体框架的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?

这博客帖子总结我们的问题有。我们可以使用包含,但只有像匹配最简单的情况。结合包括,startswith,的endsWith和的indexOf会让我们有,但需要使用标准的通配符和LINQ to实体之间的转换code。

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法 - 如果未找到该模式返回的模式第一次出现的起始位置在指定的前pression,或零,所有有效的文本和字符数据类型

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