Vivian River
Vivian River

Reputation: 32390

How to call a table-valued UDF in Entity Framework?

I've been learning to use the .net Entity Framework for an ASP.net web application. My goal is to re-write a small Classic ASP web application using ASP.net MVC.

So far, everything has been great, but I cannot, for the life of me, seem to be able to figure out how to use a table-values UDF (user-defined function) using the Entity Framework. We extensively use UDFs in-line in our SQL queries.

One of our functions returns a list of location ID numbers and corresponding location names and other data. This function is called fn_getLocationData(@year). There is a seperate list of locations for each year, so @year specifies what year to get locations for.

We have a lot of queries that look something like this:

SELECT E2L.employeeName, E2L.locationId, L.locationName
FROM
    EmployeeToLocation E2L
INNER JOIN
    fn_getLocationData(2012) L
    ON E2L.locationId = L.locationId

If I cannot find an easy way to use the results of calling fn_getLocationData in the Entity Framework, then the Entity Framework will be a complete non-starter in my organization.

I need to know how to set up my edmx model and associated code to allow me to use my UDFs. Please help.

Upvotes: 2

Views: 791

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364269

Table valued functions are not supported yet. The support was part of June 2011 CTP which will be released in .NET 4.5.

Upvotes: 1

Related Questions