linq到实体和生成的sql [英] linq to entities and generated sql

查看:96
本文介绍了linq到实体和生成的sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ado.net中对linq实体有一些问题实体框架。基本上我正在做的是:

var results =(来自公司的c
,其中c.Name.StartsWith(字母)
选择c);

并将其转换为SQL,如下所示:

WHERE(CAST(CHARINDEX(@ p,[Extent1]。[Name])AS int))= 1

这很好,但是我的表有数百万条记录,所以这个运行速度非常慢。我需要它生成的东西是这样的:

WHERE Name LIKE @p +'%'

我搜索高低,除了两者之外找不到任何解决方案使用存储过程或使用实体sql ...

有没有办法通过linq做到这一点?可能通过某种方式将linq扩展到实体linq提供程序,或以某种方式拦截命令树或生成的查询?

请帮忙!

解决方案

嗨*,

现在不可能。您可以查看 http://msdn.microsoft.com/en-us/library/bb738681.aspx 。如果您想尝试破解查询,可以尝试启动此处


I am having some problems with linq to entities in the ado.net entity framework. Basically what I'm doing is this: var results = (from c in companies where c.Name.StartsWith(letter) select c); and this gets translated to SQL as something like: WHERE (CAST(CHARINDEX(@p, [Extent1].[Name]) AS int)) = 1 which is fine but my table has millions of records so this runs VERY slow. What I need it to generate is something like: WHERE Name LIKE @p + '%' I'm searched high and low and cannot find any solutions except to either use a stored procedure or use entity sql... Is there any way to do this through linq? Possibly by somehow extending the linq to entities linq provider, or somehow intercepting the command tree or generated query? Please help!

解决方案

Hi *,

right now it's not possible. You can check i.e. http://msdn.microsoft.com/en-us/library/bb738681.aspx. If you wanna to try hack the query, you may try to start here.


这篇关于linq到实体和生成的sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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