I have a quick question here. using EF6 model first.
var db = new MyEntities(GetEntityConnectionString());
ObjectContext objectContext = ((IObjectContextAdapter)db).ObjectContext;
ObjectSet<DOCUMENT> objectSet = objectContext.CreateObjectSet<DOCUMENT>();
var results = objectSet.Where("SqlServer.DATALENGTH(it.BINARYCONTENT)>50000");
Assert.IsTrue(results.ToList().Count == 9);
var results2 = objectSet.Where(doc=>System.Data.Objects.SqlClient.SqlFunctions.DataLength( doc.BINARYCONTENT)>50000);
Assert.IsTrue(results2.ToList().Count == 9);
var results3 = db.DOCUMENTS.Where(doc => System.Data.Objects.SqlClient.SqlFunctions.DataLength(doc.BINARYCONTENT) > 50000);
Assert.IsTrue(results3.ToList().Count == 9);
The first assert succeeds, so why do I get the following exception when results2 and results 3 are executed?
An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: LINQ to Entities does not recognize the method 'System.Nullable`1[System.Int32] DataLength(Byte[])' method, and this method cannot be translated into a store expression.
Is there any way to get the other asserts to succeed?
It turns out that the answer is that I'm using the wrong function.
instead of
System.Data.Objects.SqlClient.SqlFunctions.DataLength
I should be using
System.Data.Entity.SqlServer.SqlFunctions.DataLength
located within EntityFramework.SqlServer.dll
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