How to call a stored procedure in EF Core 3.0 via FromSqlRaw

后端 未结 6 1137
失恋的感觉
失恋的感觉 2020-12-03 14:04

I recently migrated from EF Core 2.2 to EF Core 3.0.

Unfortunately, I haven\'t found a way to call a stored procedure that returns an entity.

In EF Core 2.

6条回答
  •  渐次进展
    2020-12-03 14:39

    It is extremely strange… just before a few days ago I have the same problem and follow this post. I had this call:

     public IEnumerable GetTableLastChanges(string tableName, string keyColumn, out int synchronizationVersion)
        {
            var parameters = new[] {
                new SqlParameter("@table_name", SqlDbType.VarChar) { Direction = ParameterDirection.Input, Value = tableName },
                new SqlParameter("@key_column", SqlDbType.VarChar) { Direction = ParameterDirection.Input, Value = keyColumn },
                new SqlParameter("@synchronization_version", SqlDbType.BigInt) { Direction = ParameterDirection.InputOutput, Value = 0 }
            };
    
            var changes = this.TableChanges.FromSqlRaw("[dbo].[GetTableLastChanges] @table_name, @key_column, @synchronization_version OUTPUT", parameters).ToList();
    
            synchronizationVersion = Convert.ToInt32(parameters[2].Value);
    
            return changes;
        }
    

    Right now everything is fine and this call works as expected. Therefore I should admit that there is no problem with datasets and params return for EF on Core 3.

提交回复
热议问题