How to call UDF in linq to sql query?

How does the following sql statement translate to a linq query?

select ID, Price, dbo.fGetText(DescriptionID, defaultLanguage, currentUserLanguage) from Products 

UDF fGetText is quite substantial and is used throughout the code base, so it needs to be encapsulated (like UDF or otherwise, possibly a Linq expression).

Extra round trips to the database server are not an option. There should be only one query retrieving 3 fields.

Many thanks for your help. It is very useful.

+7
linq-to-sql
source share
2 answers

Here is the MSDN article:

How to call custom Inline functions (LINQ to SQL)

Note from the same page:

Although you can call custom inline functions, functions that are included in a query whose execution is deferred are not executed until the query is executed. For more information, see Introduction to LINQ Queries.

When you call the same function outside the LINQ to SQL query, it creates a simple query to call the Method Expression

Also, take a look at the 13 minute screencast.

+3
source share

You can add UDF to a DBML LINQ to SQL file in the same way that you add tables and sprocs.

Then they become executable methods in the DataContext.

There are many articles on Google, for example this .

+2
source share

All Articles