如何使用 Entity Framework 将 byte[] 传递给存储过程

How to pass byte[] to stored procedure using Entity Framework

我有一个由 EF 自动生成的函数,它调用我的存储过程并向其传递一个字节[]:

public virtual ObjectResult<string> IPv6Country_Get(byte[] ipBytes)
{
  var ipBytesParameter = ipBytes != null ?
      new ObjectParameter("ipBytes", ipBytes) :
      new ObjectParameter("ipBytes", typeof(byte[]));

  return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<string>("IPv6Country_Get", ipBytesParameter);
}

我的存储过程是:

CREATE Procedure [dbo].[IPv6Country_Get]
(
    @ipBytes varbinary
)
AS
    SELECT
        [countrySHORT] AS Country
    FROM
        [IPv6Country]
    WHERE
        @ipBytes >= [ipFROM] AND
        @ipBytes <= [ipTO]

RETURN 0

调用 EF 函数时,存储过程仅获取@ipBytes 中数组的第一个字节。我需要更改什么才能接收完整的 byte[]?

只需添加 varbinary 的长度

CREATE Procedure [dbo].[IPv6Country_Get]
(
    @ipBytes varbinary(max)
)