को अदिश-मान समारोह कॉल करने के लिए मैं अपने DB में एक अदिश-मान समारोह है:कैसे LINQ से संस्थाओं सर्वर साइड
ALTER FUNCTION [dbo].[fx_fooFunct]
(@MyParam varchar(max))
RETURNS varchar(max)
AS
BEGIN
return @MyParam
END
मैं संस्थाओं क्वेरी के लिए एक LINQ से इस फ़ंक्शन को कॉल करें और प्राप्त करना चाहते हैं एक चर में परिणाम:
LINQ to Entities does not recognize the method 'System.Data.Objects.ObjectResult`1[System.String] ExecuteFunction[String](System.String, System.Data.Objects.ObjectParameter[])' method, and this method cannot be translated into a store expression.
अन्य मैं:
let result = this.ObjectContext.ExecuteFunction<string>("SELECT dbo.fx_fooFunct(@MyParam)", new ObjectParameter("MyParam", "hello world")).FirstOrDefault()
लेकिन, जब मैं कोड निष्पादित, मैं इस त्रुटि मिलती है एनएफओ:
यह सर्वर पर चल रही एक क्वेरी का हिस्सा है।
सभी डेटा लौटाना और ऑब्जेक्ट्स के लिए LINQ का उपयोग करना प्रदर्शन के कारण एक विकल्प नहीं है।
मुझे यकीन नहीं है कि मेरे पास ExecuteFunction
सही का रिटर्न प्रकार है, लेकिन मुझे यकीन नहीं है कि यह और क्या हो सकता है ... मैं क्या गलत कर रहा हूं?
एसक्यूएल समारोह उजागर सहायक विधि बनाएं::
public class CustomSqlFunctions
{
[EdmFunction("MyModel.Store", "fx_fooFunct")]
public static string FooFunct(string myParam)
{
throw new NotSupportedException("Direct calls not supported");
}
}
LINQ अब पढ़ना चाहिए:
संपादित
Ladislav Mrnka के जवाब की मदद से , यहाँ समाधान है
let result = CustomSqlFunctions.FooFunct("hello world")
बहुत बढ़िया अदिश महत्वपूर्ण समारोह के लिए कोई समर्थन, बहुत बहुत धन्यवाद है। मैंने समाधान के साथ अपना प्रश्न अपडेट किया है। – mcqwerty