使用SSDT作为源T4模板 [英] Using SSDT as source for T4 templates
问题描述
我有一个SQL Server数据工具(SSDT)的项目,有一些存储过程,我想生成的C#code。使用T4给他们打电话。是否有这样做的任何现有的例子吗?
I have a SQL Server Data Tools (SSDT) project that has a number of stored procedures for which I would like to generate the C# code to call them using T4. Are there any existing examples for doing this?
到目前为止,我可以为每个进程内的函数,但是我真的希望能够挖掘到的元数据SSDT会创建这样我就可以得到的参数,数据类型,并从它返回值,而不是做字符串解析。
So far, I can create a function per proc, but I'd really like to be able to tap into the meta data SSDT creates so I can get the parameters, data types, and return values from it rather than doing string parsing.
推荐答案
COOL用大写C! (但不要告诉任何人谁使用了一个ORM!)
COOL WITH A CAPITAL C! (but don't tell anyone who uses an ORM!)
要获取的数据类型等一定要抓住从MS DacFx队最新DacExtensions:
To get the datatypes etc make sure you grab the latest DacExtensions from the MS DacFx team:
https://github.com/Microsoft/DACExtensions
新的API(这亦是使用T4模板写的)使得寻找信息,你需要很多很多次简单。
The new api (which incidentally is written using T4 templates) makes finding the info you need many many times simpler.
应该有你需要在这个博客足够的信息,让你去:
There should be enough information you need in this blog to get you going:
的https://the.agilesql.club/Blogs/Ed-Elliott/DacFx-Create-tSQLt-Tests-From-A-Dacpac
唯一的区别是,你正在创建C#,而不是T-SQL,所以你不会有处理ScriptDom。
The only difference is that you are creating C# and not T-SQL so you won't have to deal with the ScriptDom.
当你做到这一点,请倾倒在github这听起来像一个非常有用的项目。
When you do this, please dump it on github it sounds like a really useful project.
这篇关于使用SSDT作为源T4模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!