有沒有辦法做到這一點?我在數據庫中有一個字符串字段,我想將其解析為我的LINQ查詢中的int屬性(是的,它必須處于IQueryable級別,而不是位于內存中)。我知道2年前EF 1.0不能做到這一點(即使LINQ to SQL開箱即用也支持此基本功能)...但是我只是想知道現在是否有人想出辦法?自定義功能映射?特殊語法?什么都沒有...更新:我嘗試了模型定義的函數,如下所示: <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."); }但它似乎不起作用。我得到運行時異常: 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) at System.Data.Common.EntitySql.SemanticAnalyzer.ConvertQueryStatementToDbExpression(Statement astStatement, SemanticResolver sr) at System.Data.Common.EntitySql.SemanticAnalyzer.AnalyzeQueryCommand(Node astExpr)
2 回答

MMMHUHU
TA貢獻1834條經驗 獲得超8個贊
關于在運行時將其添加到元數據工作空間的問題非常好,但是我不知道答案。無論如何,您將無法將其映射到,Convert.ToInt32
因為您無法EdmFunction
向該方法添加屬性。
- 2 回答
- 0 關注
- 670 瀏覽
添加回答
舉報
0/150
提交
取消