gpt4 book ai didi

c# - 使用 LINQ 搜索二进制字段

转载 作者:太空宇宙 更新时间:2023-11-03 13:54:32 26 4
gpt4 key购买 nike

我有一个表,其中包含一个包含 14 字节数据的二进制字段(称为“bin”)。我想按如下方式搜索此字段:

from row in db.users where row.bin.SequenceEqual(data) select row

“data”变量的类型是byte[]。但是当我运行“q.Count()”时,我遇到了以下错误:

LINQ to Entities does not recognize the method 'Boolean SequenceEqual[Byte](System.Collections.Generic.IEnumerable`1[System.Byte], System.Collections.Generic.IEnumerable`1[System.Byte])' method, and this method cannot be translated into a store expression.

如何检索匹配二进制数据的计数?

谢谢

最佳答案

如果您拥有数据模型,并且您的二进制数据是小型固定大小的字节数组,您可以将 SQL 数据类型从 binary(14) 更改为 char(21) ,使用 Convert.ToBase64String在进入数据库的路上,和Convert.FromBase64String在出去的路上。

切换到字符串将使您的数据可搜索:只需将您的搜索 data 编码为 base64 字符串,并在搜索条件中使用 == 运算符。

关于c# - 使用 LINQ 搜索二进制字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12713325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com