Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EF6:ObjectContext.ExecuteStoreQuery返回空列表_C#_Sql Server_Entity Framework - Fatal编程技术网

C# EF6:ObjectContext.ExecuteStoreQuery返回空列表

C# EF6:ObjectContext.ExecuteStoreQuery返回空列表,c#,sql-server,entity-framework,C#,Sql Server,Entity Framework,我有以下情况: 在数据库中: 存储过程:gp\u get\u位置 在我的项目(EF6)中,我有一个DbContext对象 public List<Location> GetLocation(int LocationId, int Top = 100) { var prmLocationID = new SqlParameter("location_id", SqlDbType.Int) { Value = LocationId };

我有以下情况:

在数据库中:

  • 存储过程:gp\u get\u位置

  • 在我的项目(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();
    }
    
    执行上下文函数:

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

    这种奇怪行为的原因可能是什么?我怎样才能找到根源呢?

    这是一个非常古老的问题,似乎从来没有人回答过。我假设你已经修好了,但以防万一,检查一下你的定位对象。确保成员是属性而不是字段

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