I have a Document class that stores the data of that document as a byte array. I need to check the size of the array, using LINQ to Entities.
I have tried the following:
[long Linq query here...] o.Data.Length < 800000)
The problem is I get the following exception:
The LINQ expression node type 'ArrayLength' is not supported in LINQ to Entities."
Is there any other way to check the size of the byte array?
Use SqlFunctions.DataLength Method (Byte[])
to compare length.
yourquery..... SqlFunctions.DataLength(o.Data) < 800000)
See: Linq2EF pitfall: Using Length property causes System.NotSupportedException
Your LINQ to Entities query is translated into SQL, provided this is possible. Since the translator does not map Array.Length to any SQL method, you cannot use it in LINQ to Entities queries.
What you can do is add a column to your table OR create a VIEW
that calculates the length and exposes it as a column. Then you can query against that field and it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With