I have been working on porting an existing Client/Server application to Silverlight where most of the data access is done via User Defined Functions (UDFs). I started using ADO.Net Data Services with Linq to SQL but soon found out that UDFs are not exposed by ADO.Net Data Services. In this particular case the data returned by the UDFs does not need to be editable. The easiest way I found to access the UDFs was to create another partial class to modify the Visual Studio generated code for the Linq to SQL model. I added [DataServiceKey("ColumnName")] to all of the function result classes and then created properties that just called the Visual Studio generated function methods. Since for my project the data is read only as long as you pick a column that is not nullable ADO.Net Data Services will expose them as entities.
For instance if you have a UDF in SQL:
CREATE FUNCTION [dbo].[fnTest
RETURNS TABLE
AS
RETURN (
SELECT Col1 = 'ABC', Col2 = 7)
Linq to SQL will generate a method fnTest() that returns type fnTestResult. So in the partial class you need to do the following:
partial class DataClassesDataContext
{
public IQueryable fnTestResults
{
get
{
return fnTest();
}
}
}
[DataServiceKey("Col1")]
public partial class fnTestResult
{
}
e4394ddf-9706-4eac-98d6-24591773b87e|0|.0
silverlight, ado.net data services, linq to sql