Subsonic 3, T4 Templates, SQLite
I want to start with how the templates will work out in an actual Visual Studio project/solution. T4 templates have a *.tt extension. You can compartmentalize code by splitting it into different include files. That's what all the *.ttinclude files are.
Make sure that the project where the templates are, have a reference to Subsonic.Core.
You will need five files:
- ActiveRecord.tt
- Context.tt
- Settings.ttinclude
- SQLite.ttinclude
- App.config
The first file you will need to configure is App.config. You will need to setup your connection string to your SQLite database.
Just make sure that the values for providerName and connectionString are correct. Now remember the value for the name attribute, because we will be using it next. We will now edit the Settings.ttinclude file.
There are four things that you will want to change. I have already changed them here for WheelMUD related settings.
- Namespace - This is the namespace where all of the code will fall into.
- ConnectionStringName - This is the value that we set up in the App.config file. This tells the templates what and where the database is.
- DatabaseName - This is something that the templates will use internally.
- ExcludeTables - This is used to exclude tables from getting processed.
Now we are set to run the templates. To run them, right click on any of the files with a *.tt extension. You will see a "Run Custom Tool" entry in the context menu.
Make sure that you run Context.tt, before you run ActiveRecord.tt. ActiveRecord.cs references code in Context.cs. The first time you run a template you will see this warning dialog:
I checked the "Do not show this message again" box, so that this wouldn't appear every time I saved or ran the temaplate. I suggest you do the same.
Once you run the ActiveRecord.tt template, you will see this:
I changed the templates a bit so that they generate code compliant to our standards. I zipped everything that is needed to make this templates run. This means that the latest version of Subsonic 3 is included as an assembly as well.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现