C# 无法使用Queryable(PageSize=1)属性检索xml列

C# 无法使用Queryable(PageSize=1)属性检索xml列,c#,asp.net-mvc-4,asp.net-web-api,entity-framework-5,odata,C#,Asp.net Mvc 4,Asp.net Web Api,Entity Framework 5,Odata,我正在尝试使用OData和ASP.NET Web API,通过实体框架从SQL Server检索行。当其中一列是xml类型时,我遇到了一个问题。如果我在以下控制器中使用[Queryable]返回整个集合,则没有问题: public class TradesController : ODataController { private readonly HermesContext _db = new HermesContext(); [Queryable] public I

我正在尝试使用OData和ASP.NET Web API,通过实体框架从SQL Server检索行。当其中一列是xml类型时,我遇到了一个问题。如果我在以下控制器中使用[Queryable]返回整个集合,则没有问题:

public class TradesController : ODataController
{
    private readonly HermesContext _db = new HermesContext();

    [Queryable]
    public IQueryable<Trade> GetTrades()
    {
        return _db.trades;
    }
}
这是因为实体框架生成的sql(通过探查器查看)是:

[trade_markup]是一种xml类型,它包含在ORDER BY子句中会导致错误。如果我删除'[Extent1].[trade_markup]ASC',并(手动)运行sql的其余部分,它将正常执行

贸易映射为:

public class tradeMap : EntityTypeConfiguration<Trade>
{
    public tradeMap()
    {
        // Primary Key
        this.HasKey(t => t.trade_reference);

        // Properties
        this.Property(t => t.trade_id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

        this.Property(t => t.trade_reference)
            .IsRequired()
            .IsFixedLength()
            .HasMaxLength(50);

        this.Property(t => t.client_application_code)
            .IsRequired()
            .IsFixedLength()
            .HasMaxLength(10);

        // Table & Column Mappings
        this.ToTable("Trade");
        this.Property(t => t.trade_id).HasColumnName("trade_id");
        this.Property(t => t.trade_reference).HasColumnName("trade_reference");
        this.Property(t => t.last_updated).HasColumnName("last_updated");
        this.Property(t => t.client_application_code).HasColumnName("client_application_code");
        this.Property(t => t.trade_markup).HasColumnName("trade_markup");
    }
}
在使用[Queryable(PageSize=1)]时,是否有办法指定希望将xml列从ORDER BY子句中排除?我希望在地图的某个地方这样做,但我不知道怎么做。

好问题

让我解释一下:当您添加PageResult或使用$skip或$top时,Web API将自动为您添加默认顺序,以便结果稳定。您可以按如下方式关闭默认顺序:

[Queryable(PageSize = 1, EnsureStableOrdering=false)]

如果您的数据库尚未对结果进行排序,您可能仍希望向IQueryable中添加某种排序。

感谢您的快速响应。这解决了我的问题。我现在得到的第一笔交易,与预期的下一笔交易的链接回来。不幸的是,我没有足够的声望去投票。
public class tradeMap : EntityTypeConfiguration<Trade>
{
    public tradeMap()
    {
        // Primary Key
        this.HasKey(t => t.trade_reference);

        // Properties
        this.Property(t => t.trade_id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

        this.Property(t => t.trade_reference)
            .IsRequired()
            .IsFixedLength()
            .HasMaxLength(50);

        this.Property(t => t.client_application_code)
            .IsRequired()
            .IsFixedLength()
            .HasMaxLength(10);

        // Table & Column Mappings
        this.ToTable("Trade");
        this.Property(t => t.trade_id).HasColumnName("trade_id");
        this.Property(t => t.trade_reference).HasColumnName("trade_reference");
        this.Property(t => t.last_updated).HasColumnName("last_updated");
        this.Property(t => t.client_application_code).HasColumnName("client_application_code");
        this.Property(t => t.trade_markup).HasColumnName("trade_markup");
    }
}
public partial class Trade
{
    public int trade_id { get; set; }
    public string trade_reference { get; set; }
    public System.DateTime last_updated { get; set; }
    public string client_application_code { get; set; }
    public string trade_markup { get; set; }
}
[Queryable(PageSize = 1, EnsureStableOrdering=false)]