希望从 .netTiers 中的 JOIN 获得强类型结果
给定一个如下查询:
SELECT table1.field1 FirstField, table2.field2 SecondField
FROM table1
INNER JOIN table2 ON table1.FK = table2.PK
WHERE table1.somefield = 'somevalue';
我的目标是使用 .netTiers 返回强类型结果集。我假设我无法使用视图,因为 WHERE
子句需要一个参数,该参数无法传递给视图。存储过程可以传递“somevalue”参数,但返回弱类型的 DataSet
或 DataReader
。
我想我只是在这里缺少一个概念。需要明确的是,我最终希望能够编写如下内容:
TList <some-entity-name> entityList = DataRepository.SomeProvider.Get( "somevalue" );
foreach ( some-entity-name entity in entityList ) {
DoSomethingWith( entity.FirstField, entity.SecondField );
}
我想避免在查询执行后涉及服务器端过滤器的解决方案;涉及的表非常大。
Given a query like:
SELECT table1.field1 FirstField, table2.field2 SecondField
FROM table1
INNER JOIN table2 ON table1.FK = table2.PK
WHERE table1.somefield = 'somevalue';
My objective is to return a strongly typed result set using .netTiers. I assume that I cannot use a view because the WHERE
clause needs a parameter, which cannot be passed to a view. A stored procedure can be passed the 'somevalue' parameter but returns a weakly typed DataSet
or DataReader
.
I figure I'm just missing a concept here. Just to be clear, what I'd like to end up with is to be able to write something like this:
TList <some-entity-name> entityList = DataRepository.SomeProvider.Get( "somevalue" );
foreach ( some-entity-name entity in entityList ) {
DoSomethingWith( entity.FirstField, entity.SecondField );
}
I'd like to avoid a solution that involves a server-side filter after the query has executed; the tables involved are very large.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个视图并使用强类型 ParameterBuilder 对象来筛选特定列上的视图。我不太记得这个对象位于哪一层。
这就是您使用它的方式:
我可能是错的,但我不相信 net-tiers 实际上用上面的方法“过滤”了 TList/VList 对象,即物体的名称会暗示什么。构建器会生成 where 子句,nettiers 使用此子句对数据库运行查询。
第二个选项是尝试生成存储过程,但前提是存储过程的结果集与数据库中的表之一的架构匹配。否则,网络层将不知道如何针对它进行生成。您可以在此处了解更多相关信息
Create a view and use the strongly typed ParameterBuilder object to filter the view on the specific column. I can't quite remember what layer this object is in.
This is how you would use it:
I may be wrong, but i do not believe net-tiers actually 'filters' the TList/VList object with the method above, which is what the name of the object would suggest. The builder generates there where clause and nettiers runs a query against your database using this clause.
Your 2nd option is to try generating a stored procedure, but only if the resultset of your stored proc matches the schema of one of the tables in your database. Otherwise, net-tiers will not know how to generate against it. You can read more on that here
如果您想要一个带有联接的 TList 集合,您需要创建一个自定义存储过程。解决方案在这里: http://benpowell.org/ paging-and-sorting-in-a-nettiers-custom-stored-procedure/
如果您有这样的场景:
只要您有了正确的外键设置,.NetTiers 将为您提供适当的方法:
还会生成一个支持分页的重载方法(遗憾的是没有 orderBy 子句)。
If you want a TList collection with a join you'll need to create a custom stored procedure. Solution here: http://benpowell.org/paging-and-sorting-in-a-nettiers-custom-stored-procedure/
If you have scenario like this:
As long as you have the correct foreign keys setup, .NetTiers will provide you with the appropriate method:
There is also an overloaded method generated that supports paging (sadly no orderBy clause).