This is the codebase for Entity Framework 6 (previously maintained at https://entityframework.codeplex.com). Entity Framework Core is maintained at https://github.com/dotnet/efcore.
Describe what is not working as expected.
Hi, I use Ef6 with Oracle.ManagedDataAccess.Client for get record from Oracle database. I have same user defined functions in Oracle for "ToString" or "ToLower" when searching in database.
I using Edmx file (Database-First) in application and I have a static class that name is OracleFunctions for using function in Edmx file like below
`
public static class OracleFunctions
{
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(Decimal? input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(Decimal input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(Double? input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(double input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(int input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(int? input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(Int16? input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(Int16 input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(byte? input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(byte input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
}
`
Forexample I using this class like below
`
public static void Main()
{
SB.DAL.Test.DbTestEntities dbTest = new SB.DAL.Test.DbTestEntities();
var getLayer = dbTest.AT_LAYER.Where(a =>
OracleFunctions.NumberToString(a.SERVICEID).Contains("1")).FirstOrDefault();
}
`
when I use Ef5 everything is well and returning me results that I want , But when I upgrade to Ef6 then error occurs and throw below exeption
An unhandled exception of type 'System.NotSupportedException' occurred in mscorlib.dll
Additional information: LINQ to Entities does not recognize the method 'System.String NumberToString(System.Decimal)' method, and this method cannot be translated into a store expression.
If you are seeing an exception, include the full exceptions details (message and stack trace).
Exception message:
An unhandled exception of type 'System.NotSupportedException' occurred in mscorlib.dll
Additional information: LINQ to Entities does not recognize the method 'System.String NumberToString(System.Decimal)' method, and this method cannot be translated into a store expression.
Stack trace:
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.DefaultTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateFunctionIntoLike(MethodCallExpression call, Boolean insertPercentAtStart, Boolean insertPercentAtEnd, Func`5 defaultTranslator)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.StringContainsTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassb.<GetResults>b__a()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassb.<GetResults>b__9()
at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1[TResult](IEnumerable`1 sequence)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
at SB.DAL.Test.Program.Main() in C:\Codes\Gits\EKON.SERVICES\Service\SB.DAL.Test\Program.cs:line 16
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Steps to reproduce
OracleFunctions.cs
public static class OracleFunctions
{
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(Decimal? input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(Decimal input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(Double? input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(double input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(int input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(int? input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(Int16? input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(Int16 input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(byte? input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
[EdmFunction("Model.Store", "TO_STRING")]
public static string NumberToString(byte input)
{
throw new NotSupportedException("bu fonksiyon desteklenmiyor");
}
}
Program.cs
public static void Main()
{
SB.DAL.Test.DbTestEntities dbTest = new SB.DAL.Test.DbTestEntities();
var getLayer = dbTest.AT_LAYER.Where(a => OracleFunctions.NumberToString(a.SERVICEID).Contains("1")).FirstOrDefault();
}
Describe what is not working as expected. Hi, I use Ef6 with Oracle.ManagedDataAccess.Client for get record from Oracle database. I have same user defined functions in Oracle for "ToString" or "ToLower" when searching in database. I using Edmx file (Database-First) in application and I have a static class that name is OracleFunctions for using function in Edmx file like below
`
`
Forexample I using this class like below
`
`
when I use Ef5 everything is well and returning me results that I want , But when I upgrade to Ef6 then error occurs and throw below exeption
An unhandled exception of type 'System.NotSupportedException' occurred in mscorlib.dll
Additional information: LINQ to Entities does not recognize the method 'System.String NumberToString(System.Decimal)' method, and this method cannot be translated into a store expression.
If you are seeing an exception, include the full exceptions details (message and stack trace).
Steps to reproduce
OracleFunctions.cs
Program.cs
DbTestEntities.edmx
Further technical details
EF version: 6.0.0.0 Database Provider:Oracle.ManagedDataAccess.Client Operating system:Windows 10 IDE:Visual Studio 2015