Byte[] comparison in Linq enumerable

被刻印的时光 ゝ 提交于 2020-01-06 07:21:26

问题


I'm trying to retrieve SQL records where the rowversion is greater than a certain value. In SQL this is trivial (WHERE RowVersion > x), however not so in Dynamic Linq queries.

In my EF model I have applied the Timestamp annotation to the appropriate column.

[Timestamp]
public byte[] RowVersion { get; set; }

And used a static Compare Extension for the byte[] comparison (source: (https://stackoverflow.com/a/42502969/3424480)

static class MiscExtension
{
    public static int Compare(this byte[] b1, byte[] b2)
    {
        if (b1 == null && b2 == null)
            return 0;
        else if (b1 == null)
            return -1;
        else if (b2 == null)
            return 1;
        return ((IStructuralComparable)b1).CompareTo(b2, Comparer<byte>.Default);
    }
}

I've tried the below style Dynamic Linq expression with no luck (maxRV is a little endian Byte[]).

.Where("RowVersion.Compare(@0) > 0", maxRV);

This throws "No applicable aggregate method 'Compare' exists" which after some researching I believe this is because 'Compare' is not a valid enumerable method. Any pointers on where I might have gone wrong / alternative approaches appreciated.

来源:https://stackoverflow.com/questions/54372442/byte-comparison-in-linq-enumerable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!