我刚刚开始使用 SubSonic 3,但在基本的插入操作上遇到了困难。
我想将一个新行插入到表中,其中所有列和值均由实体对象指定。然而,我能找到的唯一示例看起来像是您必须指定每个列和值,对我来说,这与执行原始 SQL 插入相比并不是一个很大的进步!
myDB.Insert.Into<MyTable>(m => m.Col1, m=m.Col2, etc).Values(col1Val, col2Val,...)
我没有使用 ActiveRecord 模板,我知道 2.x 可以做到这一点,而且我下载的版本(SubSonic.Core 3.0.0.3)似乎没有 Repository.tt 模板。
这可能吗?
是否有适用于 v3.0.0.3 的 Repository.tt 模板?
谢谢,
Canice。
I'm just starting to use SubSonic 3 and I'm struggling with a basic insert operation.
I would like to insert a new row into a table with all columns and values as specified by an entity object. However the only examples I can find look like you have to specify each column and value, which to me isn't a big step up from doing the raw SQL insert!
myDB.Insert.Into<MyTable>(m => m.Col1, m=m.Col2, etc).Values(col1Val, col2Val,...)
I'm not using the ActiveRecord template which I know from 2.x can do this and there doesn't seem to a Repository.tt template with the version I downloaded (SubSonic.Core 3.0.0.3).
So is this possible?
Is there a Repository.tt template available for v3.0.0.3?
Thanks,
Canice.
发布评论
评论(1)
您不需要 Repository.tt,您需要的只是实例化 SimpleRepository 的实例并调用 Insert 方法,该方法将类型作为通用参数和持久保存的实例。
你可以看一下 github 上的简单存储库测试:
https://github.com/subsonic/SubSonic -3.0/blob/master/SubSonic.Tests/Repositories/SimpleRepositoryTests.cs
You will not need a Repository.tt all you need is to instantiate an instance of SimpleRepository and call the Insert method which takes a type as generic argument and instance which is persisted.
You can take a look at the simple repository tests on github:
https://github.com/subsonic/SubSonic-3.0/blob/master/SubSonic.Tests/Repositories/SimpleRepositoryTests.cs