问题描述
我在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提供程序,或以某种方式拦截命令树或生成的查询?
请帮忙!
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 companieswhere c.Name.StartsWith(letter)select c);and this gets translated to SQL as something like: WHERE (CAST(CHARINDEX(@p, [Extent1].[Name]) AS int)) = 1which 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!
这篇关于linq到实体和生成的sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!