SQL命令有效,但与EntityFramework相同的命令不起作用?

时间:2012-02-04 16:39:31

标签: sql asp.net-mvc entity-framework

您好,

如果我在我的数据库中运行:

SELECT *
FROM 
    Ads AS a 
INNER JOIN AdCategories AS ac 
    on (ac.Id = a.CategoryId) 
INNER JOIN Location AS l 
    on (l.Id = a.UserLocationId) 
WHERE 
    (l.LevelOrder LIKE '2/3/5/%') AND 
    (a.Title LIKE '%' OR a.Description LIKE '%') AND 
    a.InactivatedDate IS NULL AND 
    a.PublishedDate IS NOT NULL AND 
    a.EndDate >= '2012-02-04 17:01:37' AND 
    a.EndDate >= '2011-11-04 16:55:26' AND 
    ac.LevelOrder Like '7/15/33/36_%'

这将返回2行,但在使用Entity Framework

运行相同的命令时
context.CreateQuery<Ad>(sqlCommand, parameters.ToArray()); 
output = ads.ToList(); 

我一无所获?

这就是SQL语句的样子:

SELECT VALUE a 
FROM 
    Ads AS a 
INNER JOIN AdCategories AS ac 
    on (ac.Id = a.CategoryId) 
INNER JOIN Location AS l 
    on (l.Id = a.UserLocationId) 
WHERE 
    (l.LevelOrder LIKE @locationLevelOrder0) AND 
    (a.Title LIKE @searchS OR a.Description LIKE @searchS) AND 
    a.InactivatedDate IS NULL AND 
    a.PublishedDate IS NOT NULL AND 
    a.EndDate >= @CurrentTime AND 
    a.EndDate >= @fetchAdsTo AND 
    ac.LevelOrder Like @categoryLevelOrder

参数如下所示:

  1. LocationLevelOrder0 = 2/3/5/%
  2. searchS = %
  3. CurrentTime = {2012-02-04 17:31:34}
  4. fetchAdsTo = {2011-11-04 17:31:34}
  5. categoryLevelOrder = 7/15/33/36/_%
  6. 为什么我在SQL管理器中没有使用Entity Framework获得任何结果?选择价值代表什么?如果我删除它将会抛出异常?

1 个答案:

答案 0 :(得分:1)

首先在查询中将LevelOrder与'7/15/33/36_%'进行比较,在第二个中将7/15/33/36/_%与另一个字符串进行比较。这是转录错误还是问题?