k.c.
k.c.

Reputation: 1835

How to handle the Sql Version and C# byte array in Linq queries

We use entity framework to store our entities in the database. We use the repository pattern to wrap quite complicated Linq-queries. We want to unit test these queries against simple in memory collections. This is all fine and good until we ran into queries that order on the sql-type rowversion to find the last added record in a set. EntityFramework is capable to covert this Linq to SQL.

The row version is converted to a byte array by C# as it is too big to fit a ulong(?) when objects are rehydrated from the database.

So we add these byte arrays to our in memory test data. However if we run queries against our in memory set, the Linq explodes as an array of bytes is not comparable so it can not perform the needed sort.

So we wrote a comparer that works on byte arrays, when we use this comparer in our queries they work fine in memory.

But now LinqToEntities unable to handle the queries with the comparer.

We seem stuck in a catch 22…

Has anybody a solution that works in memory and in LinqToEntities?

Upvotes: 0

Views: 763

Answers (1)

NetMage
NetMage

Reputation: 26936

This seems like a work around if you combine it with implementing Compare(this byte[]... as your comparer:

https://stackoverflow.com/a/19402565/2557128

Upvotes: 0

Related Questions