有沒(méi)有辦法做到這一點(diǎn)?我在數(shù)據(jù)庫(kù)中有一個(gè)字符串字段,我想將其解析為我的LINQ查詢(xún)中的int屬性(是的,它必須處于IQueryable級(jí)別,而不是位于內(nèi)存中)。我知道2年前EF 1.0不能做到這一點(diǎn)(即使LINQ to SQL開(kāi)箱即用也支持此基本功能)...但是我只是想知道現(xiàn)在是否有人想出辦法?自定義功能映射?特殊語(yǔ)法?什么都沒(méi)有...更新:我嘗試了模型定義的函數(shù),如下所示: <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."); }但它似乎不起作用。我得到運(yùn)行時(shí)異常: 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貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊
關(guān)于在運(yùn)行時(shí)將其添加到元數(shù)據(jù)工作空間的問(wèn)題非常好,但是我不知道答案。無(wú)論如何,您將無(wú)法將其映射到,Convert.ToInt32
因?yàn)槟鸁o(wú)法EdmFunction
向該方法添加屬性。
添加回答
舉報(bào)
0/150
提交
取消