小编shi*_*esh的帖子

Linq加入COUNT

我有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)
  1. 连接必须是左连接:如果没有属于某个论坛的帖子,则应检索论坛字段,但PostCount字段应为0.
  2. 结果集必须是不同的(join给我完整的交叉......或者它是如何调用的)

c# linq entity-framework

10
推荐指数
1
解决办法
2万
查看次数

Linq-to-Entities离开JOIN

这是我的查询:

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)

c# linq-to-entities entity-framework

7
推荐指数
1
解决办法
4282
查看次数

检索绑定值的子字符串

我绑定一些数据来控制,但是想要将特定字段的字符数限制为30个第一个字符.

如果有可能的话,我想在aspx页面上这样做.

我试过这个:

Text='<%# String.Format("{0}", Eval("Title")).Substring(0,30) %> '
Run Code Online (Sandbox Code Playgroud)

但得到了这个错误:

索引和长度必须指向字符串中的位置.参数名称:长度

c# asp.net data-binding

4
推荐指数
1
解决办法
3060
查看次数

动态添加iframe和段落元素

我想将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的正文)中

html javascript

2
推荐指数
1
解决办法
1万
查看次数

实体框架:删除记录及其子记录

我有一个有3列的表: ID, Name, ParentID.

如何删除所有子项(n级深)的特定记录?

使用Entity Framework 3.5.

c# entity-framework

2
推荐指数
1
解决办法
4539
查看次数

HTML编码服务器端与客户端

我想在我的页面上启用评论发布,所以我需要在发送帖子并插入数据库之前执行一些html编码.

这个理想的一面是什么?
Sever方面(我使用asp.net)或客户端(javascript)?

javascript asp.net html-encode

1
推荐指数
2
解决办法
5128
查看次数