Subsonic 2.2 将连接的表列绑定到网格
我对亚音速还很陌生,发现最简单的事情有点棘手。 我有一个简单的查询,它连接两个表:配置文件和订阅。
ProfileCollection profiles =
new Select().From<Profile>()
.InnerJoin(Subscription.ProfileIdColumn,Profile.ProfileIDColumn )
.Where(Subscription.ExpiryDateColumn).IsLessThan(Date)
.ExecuteAsCollection <ProfileCollection > ();
return profiles;
我想在我的网格中显示以下列、Profile.Name 和 Subscription.ExpiryDate 以及其他一些列。
以前我使用过 LLBLGen,我可以做类似的事情(请注意这是伪代码):
<repeater>
<itemitemplate>
<%#Eval("Name")%>
<%#Eval("Subscription.ExpiryDate")%>
</itemitemplate>
</repeater>
但是我收到了一个错误,类似于
订阅不是会员 简介
,以便它在选择中具有列名称,但我也遇到了上述错误。
ProfileCollection profiles =
new Select(Subscription.ExpiryDateColumn.PropertyName,
Profile.NameColumn.PropertyName).From<Profile>()
.InnerJoin(Subscription.ProfileIdColumn,Profile.ProfileIDColumn )
.Where(Subscription.ExpiryDateColumn).IsLessThan(Date)
.ExecuteAsCollection <ProfileCollection > ();
return profiles;
这似乎很常见,我发现多个地方需要绑定到网格并从连接表中调用列,但这似乎不可能。
有人可以告诉我我缺少什么,或者让我知道用亚音速将连接表行绑定到网格的最佳方法吗?
我的解决方案 好的,从下面的答案中我已经确定我需要执行以下操作: 我已经使用了 *,所以我可以带回
Dataset profiles =
new Select("Subscription.*","Profile.*").From<Profile>()
.InnerJoin(Subscription.ProfileIdColumn,Profile.ProfileIDColumn )
.Where(Subscription.ExpiryDateColumn).IsLessThan(Date)
.ExcecuteDataset();
return profiles;
网格中的所有行,现在我可以绑定 <%#Eval("Name")%>从配置文件表和 <%#Eval(Subscription.ExpiryDate")%> 从订阅到我的网格
还有更多建议吗? 尽管上述方法有效,但我不喜欢使用“订阅”。", "Profile." 在选择中,我宁愿使用一些强类型值,以防发生某些变化,这样我就会得到编译错误,而不是在尝试运行查询时崩溃!
谢谢
Bex
I am still reasonably new to subsonic and finding the simplest things a little tricky.
I have a simple query that joins two tables, Profile and Subscription.
ProfileCollection profiles =
new Select().From<Profile>()
.InnerJoin(Subscription.ProfileIdColumn,Profile.ProfileIDColumn )
.Where(Subscription.ExpiryDateColumn).IsLessThan(Date)
.ExecuteAsCollection <ProfileCollection > ();
return profiles;
I want to display the following columns in my grid, Profile.Name and Subscription.ExpiryDate and maybe a few others.
Previously I have used LLBLGen and I could do something like (please note this is pseudo code):
<repeater>
<itemitemplate>
<%#Eval("Name")%>
<%#Eval("Subscription.ExpiryDate")%>
</itemitemplate>
</repeater>
But I get an error something along the lines of
Subscription isnt a member of
Profile
I tried updating my query so it had the column names in the select, but I also got the above error.
ProfileCollection profiles =
new Select(Subscription.ExpiryDateColumn.PropertyName,
Profile.NameColumn.PropertyName).From<Profile>()
.InnerJoin(Subscription.ProfileIdColumn,Profile.ProfileIDColumn )
.Where(Subscription.ExpiryDateColumn).IsLessThan(Date)
.ExecuteAsCollection <ProfileCollection > ();
return profiles;
It seems like something really common and I am finding multiple places where I need to bind to a grid and call columns from the joining table but it doesn't seem possible.
Can someone either tell me what I'm missing or let me know the best way to bind joined table rows to grids with subsonic?
My Solution
Ok from the answers below I have established I need to do the following:
I have used * so I can bring back all rows
Dataset profiles =
new Select("Subscription.*","Profile.*").From<Profile>()
.InnerJoin(Subscription.ProfileIdColumn,Profile.ProfileIDColumn )
.Where(Subscription.ExpiryDateColumn).IsLessThan(Date)
.ExcecuteDataset();
return profiles;
In my grid I can now bind <%#Eval("Name")%> from the profile table and <%#Eval(Subscription.ExpiryDate")%> from subscription to my grid
Any more suggestions? Even though the above works I am not happy using "Subscription.", "Profile." in the select, I'd rather use some strongly typed values incase something changes so I get compile errors rather than it just crashing out when it tries and runs the query!
Thanks
Bex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要查看 SubSonic 查询工具 来执行连接,附加的链接有很多示例,应该帮助。如果您必须使用 SubSonic 进行复杂的联接,我建议您将逻辑移至存储过程。下面将创建一个查询,返回您在 Select() 方法中列出的列。
例子:
You need to look at the SubSonic Query Tool to perform joins, the attached link has a lot of sample that should help. If you have to do complex joins with SubSonic, I suggest you move the logic to a stored procedure. Below, will create a query that returns the colums you list in the Select() method.
Example: