0

I have a sql function in a database that is mapped to an entity framework model.

When I add it my model, it returns a result which is of complex data type (usually named functionName_Result).

Is it possible to make such a function so that its return type is one of my model entities?

For example if I have a model-first entity framework model that contains A entity, can I make sql function in the database that returns A class instance?

2 Answers 2

1

You should write your SQL table valued function so that it returns the data exactly matching your model classes. Usually you have Table1 class in your model and Table1 table in the database and the table valued function FGetTable1Data returns SELECT * FROM Table1 ... - the names of columns in SQL returned resultset must exactly match with the names and data types in your model.

If you have model-first see the following link: http://msdn.microsoft.com/en-us/data/hh859577.aspx.

In the model-first approach you will have to do it in Visual Studio in the interactive model designer:

  • Right-click the design surface and select Model Browser
  • In Model Browser, select Function Imports, and then double-click the your function
  • In the Edit Function Import dialog box, select Entities and choose the entity you want to be the return type of your table-valued function
Sign up to request clarification or add additional context in comments.

Comments

0

Yes, you should be able to do that

http://msdn.microsoft.com/en-us/library/vstudio/cc716672%28v=vs.100%29.aspx

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.