我在这里有一个简单的问题.
首先使用EF6模型.
首先使用EF6模型.
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);
第一个断言成功,那么为什么在执行results2和result 3时会出现以下异常?
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.
有没有办法让其他断言成功?