Entity Framework - Table Valued Function

User-defined functions that return a table data type is called table valued function. TVFs can be powerful alternatives to views. The table returned by a user-defined function can be referenced in the FROM clause of a Transact-SQL statement, but stored procedures that return result sets cannot.

TVFs are currently only supported in the Database First workflow.

TVF support was introduced in Entity Framework version 5. To use the new features like table-valued functions, enums, and spatial types you must use .NET Framework 4.5. Visual Studio 2012 targets .NET 4.5 by default.

TVFs vs. Views
TVFs and Views are similar in that they are both composable.  That means function or the view can be used anywhere within the body of a T-SQL query.  The major differences are, first, that SQL Views can only have one SELECT statement, whereas TVFs can have multiple statements as well as procedural code.  This makes it possible to design more complex logic with TVFs than with Views.  TVFs can take parameters, whereas Views cannot.

TVFs vs. Stored Procedures
TVFs and stored procedures may both contain procedural code, but unlike stored procedures, TVFs can be used anywhere in a query.  This allows us to both compose queries using TVFs and filter the result set of a TVF.  One advantage of stored procedures over TVFs is that stored procedures are capable of returning multiple result sets.

Example table valued function

EntityFramework - Table Valued Function


Click Here for more detail in table valued function.

Click Here to go through step by step by creating project

Praesent mattis

Pellentesque viverra vulputate enim. Aliquam erat volutpat. Pellentesque tristique ante ut risus. Quisque dictum. Integer nisl risus, sagittis convallis, rutrum id, elementum congue, nibh. Suspendisse dictum porta lectus. Donec placerat odio vel elit.

Read More