Last post Feb 04, 2015 12:38 AM by pka246
Feb 01, 2015 02:10 AM|AnushaB|LINK
I am using EF 6 and trying to filter a int column with Starts with.
Using : Visual Studio 2013, Oracle Data Base, MVC 5.0, EF 6.0
var results = (from ec in context.abcd
where ec.INACTIVEFLAG == (inactiveFlag == true ? 1 : 0) &&
This is throwing an exception as below
An exception of type 'System.NotSupportedException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The specified method 'System.String StringConvert(System.Nullable`1[System.Double])' on the type 'System.Data.Entity.SqlServer.SqlFunctions' cannot be translated into a LINQ to Entities store expression.
Any help is greatly appreciated
Feb 01, 2015 02:29 AM|Careed|LINK
I believe that you need to use System.Data.Objects.SqlServer to use within a LINQ to Entities query.
Feb 01, 2015 02:46 AM|AnushaB|LINK
I tried .ToString() instead of String Convert. ToString is working in EF 6
Feb 01, 2015 02:50 AM|Careed|LINK
In general, you do not really need to use the SqlFunctions and it's probably a good practice not to do so in case you end up using other data sources besides SQL Server.
Feb 04, 2015 12:38 AM|pka246|LINK
You need to convert double into string outside query:
string filterString = Convert.ToString((double)ec.CUSTOMERNUMBER)
var results = (from ec in context.abcd where ec.INACTIVEFLAG == (inactiveFlag == true ? 1 : 0) &&
filterString.StartsWith(filter) orderby ec.CUSTOMERNUMBER select ec);