CLR static data table-valued function

Source: Internet
Author: User

The first two days insus.net implement a function of "provide read-only data in the database" http://www.cnblogs.com/insus/p/4384411.html, in the database to provide static data for the program.
It is implemented in CLR stored procedures. Now you want to use a different way to solve. If providing these static numbers needs to be combined with other data joins, such as the previous stored procedure, some are not very good operation. Then we can implement it in table-valued function.

Create a model:


Then create an entity:


Open the SqlFunction class and write the table-valued function:


To copy code:

[SqlFunction (DataAccess =Dataaccesskind.none, FillRowMethodName="fillrow_1a", TableDefinition="Id tinyint,name NVARCHAR (+), [key] NVARCHAR (+)")   ]     Public StaticIEnumerable tvf_siteinfor () {fruitentity Fe=Newfruitentity (); returnfe.           GetData (); }    Private Static voidFILLROW_1A (ObjectSource outSqlByte ID, outSqlChars name, outSqlChars Key) {Si obj=(Si) source; ID=NewSqlByte (obj.        ID); Name=NewSqlChars (obj.        Name); Key=NewSqlChars (obj.    Key); }
View Code


Deploy to SQL:



To copy code:

IF EXISTS(SELECT *  fromSys.objectsWHEREName= 'tvf_siteinfor')    DROP FUNCTIONtvf_siteinfor;GOIF EXISTS(SELECT *  fromSys.assembliesWHEREName= 'FRUITCLR')    DROPASSEMBLY fruitclr;GOCREATEASSEMBLY fruitclr from 'E:\FruitClr.dll'  withPermission_set=SAFE;GOCREATE FUNCTIONtvf_siteinfor ()RETURNS TABLE(IdTINYINT,    [Name] NVARCHAR( -),    [Key] NVARCHAR( -))  asEXTERNAL NAME[FRUITCLR]. Userdefinedfunctions.tvf_siteinfor; GO
View Code


Execution Result:

CLR static data table-valued function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.