Database objects are commonly implemented using some dialect of the SQL language. This is true with SQL Server as well, and as we have just reviewed, the Visual Studio database project allows you to craft your database objects using SQL. But using that same project, you can also design database objects using C#.
SQL Server 2005 introduced the capability of authoring SQL objects in managed code. So, instead of using Transact SQL, you can actually write your stored procedures, queries, views, and so on using C#. These are run under the auspices of SQL Server’s own version of the .NET Common Language Runtime (CLR).
The SQL Server CLR supports a variety of object types that can be written in C#:
Stored procedures
Triggers
Aggregates
User-defined functions
User-defined types
The following sections look at how to go about creating a straightforward stored procedure using C# instead of T-SQL.