我有2张桌子,论坛和帖子.
我想要使用新的额外字段检索所有论坛字段:计算属于此论坛的所有帖子.
我现在有这个:
var v =(from forum in Forums
join post in Posts on forum.ForumID equals post.Forum.ForumID
select new
{
forum, //Need to retrieve all fields/columns from forum
PostCount = //count all post that belong to this forum with a condition: count it only if post.Showit==1
}
).Distinct()
Run Code Online (Sandbox Code Playgroud)
这是我的查询:
from forum in Forums
join post in Posts on forum equals post.Forum into postGroup
from p in postGroup
where p.ParentPostID==0
select new
{
forum.Title,
forum.ForumID,
LastPostTitle = p.Title,
LastPostAddedDate = p.AddedDate
}).OrderBy(o=>o.ForumID)
Run Code Online (Sandbox Code Playgroud)
目前,Join不是左连接,这意味着如果某个论坛没有属于它的帖子,则不会返回.
没有帖子的论坛必须返回post属性的null(或默认)值.
UPDATE
结果集应该是这样的:
ForumId | ForumTitle | LastPostTitle | LastPostAddedDate
--------+------------+---------------+------------------
4 | Sport | blabla | 12/4/2010
4 | Sport | blabla | 15/4/2010
6 | Games | blabla | 1/5/2010
7 | Flame | |
Run Code Online (Sandbox Code Playgroud) 我绑定一些数据来控制,但是想要将特定字段的字符数限制为30个第一个字符.
如果有可能的话,我想在aspx页面上这样做.
我试过这个:
Text='<%# String.Format("{0}", Eval("Title")).Substring(0,30) %> '
Run Code Online (Sandbox Code Playgroud)
但得到了这个错误:
索引和长度必须指向字符串中的位置.参数名称:长度
我想将iframe元素添加到页面,然后<p>在iframe中添加元素.
我试过这个:
var iframe = document.createElement('iframe');
iframe.frameBorder = 1;
iframe.width = "500px";
iframe.height = "250px";
iframe.id = "iframe";
var p = document.createElement('p');
iframe.appendChild(p);
document.getElementById("div").appendChild(iframe); //this is a div that I have in body.
Run Code Online (Sandbox Code Playgroud)
iframe已添加到页面中,但P未添加到iframe(iframe的正文)中
我有一个有3列的表: ID, Name, ParentID.
如何删除所有子项(n级深)的特定记录?
使用Entity Framework 3.5.
我想在我的页面上启用评论发布,所以我需要在发送帖子并插入数据库之前执行一些html编码.
这个理想的一面是什么?
Sever方面(我使用asp.net)或客户端(javascript)?