0

Ok, so I'm not using Sql Client.

I have an .edmx file in my project and in it are the tables, the views and the stored procedures. I know how to call them from my project. But I have some functions in the Server Explorer. How to call them via code?

5
  • You want to call a stored procedure using EF? Which version of EF are you using? Commented Jun 13, 2012 at 11:29
  • @DarinDimitrov No. I want to call a function. Commented Jun 13, 2012 at 11:30
  • A function? Never heard of such notion in a SQL database. Commented Jun 13, 2012 at 11:30
  • @DarinDimitrov Can you see this? msdn.microsoft.com/en-us/library/dd456857.aspx Commented Jun 13, 2012 at 11:31
  • @DarinDimitrov And here: google.com/… Commented Jun 13, 2012 at 11:32

2 Answers 2

1

You just need to add those function to EDMX in Wizard (update model from database) and after that you have to manually create static function accepting parameters with same names and marked with EdmFunction attribute (examples in this question). Now you have mapped function which can be used inside Linq-to-entities queries. EF provider will correctly translate your CLR call to SQL function call in SQL query.

EF 4.0 doesn't support table valued functions (this support is added in EF 4.5 / .NET 4.5). Also this mapping works only with EDMX - not with code first.

Sign up to request clarification or add additional context in comments.

2 Comments

But I can only add views, tables and stored procedures to my .edmx file.
Functions which can be imported will be under stored procedures.
0

What I did was writing a stored procedure with the same code as the stored procedure and import it in the .edmx file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.