KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is there any way of doing this at all? I have a string field in the DB and I want to parse it into a int property in my LINQ query (yes, it must be at the IQueryable level, not in memory). I know 2 years ago EF 1.0 couldn't do this (even though LINQ to SQL supported this basic functionality out of the box)...but I'm just wondering if anyone has come up with a way of doing this at this point? Custom function mappings? Special syntax? Anything at all.... UPDATE: I tried a model defined function as follows: <Function Name="ConvertToInt32" ReturnType="Edm.Int32"> <Parameter Name="v" Type="Edm.String" /> <DefiningExpression> CAST(v AS INT) </DefiningExpression> </Function> [EdmFunction("Model.Repository", "ConvertToInt32")] public static int ConvertToInt32(string value) { throw new InvalidOperationException("Only valid when used as part of a LINQ query."); } but it doesn't seem to work. I get the runtime exception: ErrorDescription=Type 'INT' could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly. StackTrace: at System.Data.Common.EntitySql.SemanticAnalyzer.ConvertTypeName(Node typeName, SemanticResolver sr) at System.Data.Common.EntitySql.SemanticAnalyzer.ConvertTypeExprArgs(BuiltInExpr astBuiltInExpr, SemanticResolver sr) at System.Data.Common.EntitySql.SemanticAnalyzer.<CreateBuiltInExprConverter>b__73(BuiltInExpr bltInExpr, SemanticResolver sr) at System.Data.Common.EntitySql.SemanticAnalyzer.ConvertBuiltIn(Node astExpr, SemanticResolver sr) at System.Data.Common.EntitySql.SemanticAnalyzer.Convert(Node astExpr, SemanticResolver sr) at System.Data.Common.EntitySql.SemanticAnalyzer.ConvertValueExpression(Node astExpr, SemanticResolver sr)
Tags (comma-separated)
Save Edits
Cancel