希望从 .netTiers 中的 JOIN 获得强类型结果

发布于 2024-08-04 19:36:56 字数 694 浏览 3 评论 0原文

给定一个如下查询:

SELECT table1.field1 FirstField, table2.field2 SecondField
    FROM table1
    INNER JOIN table2 ON table1.FK = table2.PK
    WHERE table1.somefield = 'somevalue';

我的目标是使用 .netTiers 返回强类型结果集。我假设我无法使用视图,因为 WHERE 子句需要一个参数,该参数无法传递给视图。存储过程可以传递“somevalue”参数,但返回弱类型的 DataSetDataReader

我想我只是在这里缺少一个概念。需要明确的是,我最终希望能够编写如下内容:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦 2024-08-11 19:36:56

创建一个视图并使用强类型 ParameterBuilder 对象来筛选特定列上的视图。我不太记得这个对象位于哪一层。

这就是您使用它的方式:

MyViewParameterBuilder builder = new MyViewParameterBuilder();
builder.AppendEquals(TableColumn.Column, "value");
DataRepository.MyViewEntityProvider.Find(builder.GetParameters());

我可能是错的,但我不相信 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:

MyViewParameterBuilder builder = new MyViewParameterBuilder();
builder.AppendEquals(TableColumn.Column, "value");
DataRepository.MyViewEntityProvider.Find(builder.GetParameters());

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

一人独醉 2024-08-11 19:36:56

如果您想要一个带有联接的 TList 集合,您需要创建一个自定义存储过程。解决方案在这里: http://benpowell.org/ paging-and-sorting-in-a-nettiers-custom-stored-procedure/

如果您有这样的场景:

  • Account (PK AccountId)
  • Client (PK ClientId)
  • ClientAccount (PK ClientId, AccountId)

只要您有了正确的外键设置,.NetTiers 将为您提供适当的方法:

AccountService s = new AccountService();
TList<Account> accountCollection = s.GetByClientIdFromClientAccount(1);

还会生成一个支持分页的重载方法(遗憾的是没有 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:

  • Account (PK AccountId)
  • Client (PK ClientId)
  • ClientAccount (PK ClientId, AccountId)

As long as you have the correct foreign keys setup, .NetTiers will provide you with the appropriate method:

AccountService s = new AccountService();
TList<Account> accountCollection = s.GetByClientIdFromClientAccount(1);

There is also an overloaded method generated that supports paging (sadly no orderBy clause).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文