ASP.NET MVC搜索页面 - 整数StartsWith LINQ的+ EF4 [英] ASP.NET MVC Search Page - Integer StartsWith On Linq + EF4

查看:184
本文介绍了ASP.NET MVC搜索页面 - 整数StartsWith LINQ的+ EF4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,在我过去后我是问如何使用LINQ和EF4(的在这里看到),最后想出了建立表达式作为一个字符串,并将其解析到使用动态LINQ库表达式的解决方案。

So, in my last post I was asking how to build a dynamic search filter using LINQ and EF4 (See Here) and finally came up with the solution of building the expression as a string and parse it to an expression using the Dynamic LINQ library.

我的解决了这个问题。我能够生成一个表达式来; Func键< TSource,OUT BOOL>> ,并把它传递给其中() DbSet 方法。我也尝试这种使用MySQL作为背后EF4数据库做的。

I that solved the problem. I was able to generate a Expression<Func<TSource, out bool>> and pass it to the Where() method of the DbSet. I am also trying to do this using MySql as a database behind EF4.

当我试图字符串操作应用到整数,如搜索数据库记录的问题就来了这连续。编号开头为1234

The problem came when I tried to apply string operations to integers, like searching a database record which consecutive number starts with 1234.

我最初的表达是这样的: record.ConsecutiveNumber.ToString()StartsWith(1234)。可悲的是,正如所料,事情没那么容易,因为EF4未能查询 DbSet ,出现异常:

My initial expression was something like: record.ConsecutiveNumber.ToString().StartsWith("1234"). Sadly, as expected, things were not that easy as EF4 fails to query the DbSet with exception:

LINQ实体无法识别
中的方法System.String的ToString()'
的方法,并且这种方法不能为
翻译成一个商店的表达。

"LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression."

一些谷歌搜索,我发现,这是一个普遍的问题后。但是拜托!是否有执行可以搜索记录与1234开始连续编号搜索功能的一种方式?

After some Google search I found that this is a common problem. But C'MON! Is there a way to perform a search function that can search records with a consecutive number starting by "1234"?

利弊如何实现与EF4搜索功能?这是一个属性过滤器。如果我想添加多个过滤器?上帝,我的头好痛...:/

How pros implement search features with EF4? This is with a single property filter. What if I wanna add multiple filters? God, my head hurts... :/

感谢

编辑:

思想#1:怎么样一个存储过程?什么叫从LINQ的一个M​​ySQL存储过程? ?我瞄准太高

Thought #1: What about a stored procedure? What about calling a MySql stored procedure from Linq? Am I aiming way too high?

推荐答案

你有没有看动态的LinQ库:
HTTP: //weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

Have you looked at the Dynamic LinQ Library: http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

和你的问题
如何使用"包含"或QUOT;喜欢"在一个动态的LINQ查询?

此前我已经得到的代码,这个lib和刚刚往里一看,这是很容易。

Previously I have gotten the code for this lib and just taken a look inside, it is pretty easy to follow.

这篇关于ASP.NET MVC搜索页面 - 整数StartsWith LINQ的+ EF4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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