EF6:ObjectContext.ExecuteStoreQuery返回空列表



我有以下情况:

在数据库中:

  • 存储过程:gp_get_location

  • 在我的项目(EF6)中,我有一个DbContext对象

    public List<Location> GetLocation(int LocationId, int Top = 100)
    {
        var prmLocationID = new SqlParameter("location_id", SqlDbType.Int)
        {
            Value = LocationId
        };
        var prmTop = new SqlParameter("top", SqlDbType.Int)
        {
            Value = Top
        };
        ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 300;
        var query = ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<Location>(@"EXECUTE [dbo].[gp_get_location] @location_id, @top", prmLocationID, prmTop);
        return query.ToList();
    }
    

在管理工作室中执行存储过程,如下所示:

exec gp_get_location X, 100 -- returns 100 results
exec gp_get_location Y, 100 -- returns 100 results

执行上下文函数:

GetLocation(X, 100) //returns 100 results
GetLocation(Y, 100) //NOT CORRECT - returns 0 results, no exception no warning just 0 

这种奇怪行为的原因是什么?我该如何找出根源?

这是一个非常古老的问题,看起来从未得到过回答。我假设你已经修复了它,但以防万一,检查一下你的Location对象。请确保成员是"属性"而不是"字段"。

最新更新