当一起使用INCLUDE和SKIP时,实体框架会生成无效的Firebird查询

时间:2012-01-17 04:37:02

标签: entity-framework firebird

模特:

[Table("RECIPE")]
public class Recipe
{

    [Key, Column("ID"), DatabaseGenerated(DatabaseGeneratedOption.None), Required]
    public int ID { get; set; }

    [Column("NAME")]
    public string Name { get; set; }


    public virtual ICollection<Ingredient> Ingredients { get; set; }

}

[Table("INGREDIENTS")]
public class Ingredient
{

    [Key, Column("ID"), DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int ID { get; set; }

    [Column("RECIPE"), Required]
    public int RecipeID { get; set; }

    [ForeignKey("RecipeID")]
    public virtual Recipe Recipe { get; set; }

    [Column("NAME")]
    public string Name { get; set; }

}


public class RecipeCtx : DbContext
{

    public DbSet<Recipe> Recipes { get; set; }
    public DbSet<Ingredient> Ingredients { get; set; }


}

控制器:

    public ViewResult Index()
    {

        var ingredients = (from ing in db.Ingredients.Include(c => c.Recipe) orderby ing.ID select ing)
            .Skip(20)
            .Take(20)
            .ToList();

        return View(ingredients);

    }

生成的查询:

SELECT 
"Limit1"."Extent1"."ID" AS "ID", 
"Limit1"."Extent1"."RECIPE" AS "RECIPE", 
"Limit1"."Extent1"."NAME" AS "NAME", 
"Limit1"."Extent2"."ID" AS "ID1", 
"Limit1"."Extent2"."NAME" AS "NAME1"
FROM ( SELECT FIRST (20) SKIP (20) "Extent1"."ID" AS "ID1", "Extent1"."RECIPE" AS "RECIPE", "Extent1"."NAME" AS "NAME1", "Extent2"."ID" AS "ID2", "Extent2"."NAME" AS "NAME2"
    FROM  "INGREDIENTS" AS "Extent1"
    INNER JOIN "RECIPE" AS "Extent2" ON "Extent1"."RECIPE" = "Extent2"."ID"
    ORDER BY "Extent1"."ID" ASC
)  AS "Limit1"

例外:

{"An error occurred while executing the command definition. See the inner exception for details."}

{"Dynamic SQL Error\r\nSQL error code = -104\r\nToken unknown - line 2, column 19\r\n."}

如果我删除了跳过它可以正常工作。

我正在使用:

Firebird Server Version 2.5.1.26351 (the latest version)

FirebirdClient - ADO.NET Data Provider version 2.7.0.0 (the latest version)

我该怎么做才能解决这个问题?

2 个答案:

答案 0 :(得分:3)

这是提供商的错误。将其报告给tracker.firebirdsql.org

答案 1 :(得分:-1)

只需SELECT tab.ID - 您无需将其与.

嵌套

在您的示例中,工作语句将如下:

SELECT tab.ID FROM (SELECT FIRST 50 SKIP 100 ID FROM CALL_LOG) AS tab