我有一个linq查询函数,如(简化):
public IList<Document> ListDocuments(int? parentID)
{
return (
from doc in dbContext.Documents
where doc.ParentID == parentID
select new Document
{
ID = doc.ID,
ParentID = doc.ParentID,
Name = doc.SomeOtherVar
}).ToList();
}
Run Code Online (Sandbox Code Playgroud)
现在由于某种原因,当我为parentID传递null(当前只有具有null parentID的数据)时,我没有得到任何结果.
我将此查询复制并粘贴到LinqPad中并运行以下命令:
from doc in dbContext.Documents
where doc.ParentID == null
select doc
Run Code Online (Sandbox Code Playgroud)
我按预期得到了一个结果集......
实际的查询已经离开了连接和其他连接,但我已经删除它们并测试它并获得相同的结果,因此连接不会影响任何东西.该应用程序和LinqPad也连接到同一个数据库.
编辑:在应用程序查询中仅使用"null"进行测试,并按预期返回结果,因此问题是使用null vs int?.我已经更新了问题,使其对具有相同问题的其他人更有用,可以找到这个帖子.
我有一个基本的查询,从6秒到1秒只需将一个连接更改LEFT JOIN为LEFT HASH JOIN"LEFT LOOP JOIN".任何人都可以解释为什么这会导致性能如此大幅度增加以及为什么SQL的优化器不能自己解决它?
这大致是SQL的样子:
SELECT
a.[ID]
FROM
[TableA] a
LEFT HASH JOIN
[TableB] b
ON b.[ID] = a.[TableB_ID]
JOIN
[TableC] c
ON c.[ID] = a.[TableC_ID]
WHERE
a.[SomeDate] IS NULL AND
a.[SomeStatus] IN ('X', 'Y', 'Z') AND
c.[SomethingElse] = 'ABC'
Run Code Online (Sandbox Code Playgroud)
表A和B在所有ID字段上都有数百万条记录和索引.使用SQL Server 2005.
编辑:一位同事提出了LEFT LOOP JOIN,它似乎让它更快...... SQL不是我的优势之一,所以我试图理解这些"暗示"是如何帮助的.
我需要显示经过时间跨度的最简单版本.有没有准备好的事情呢?
样品:
HH:mm:ss
10:43:27 > 10h43m27s
00:04:12 > 4m12s
00:00:07 > 7s
Run Code Online (Sandbox Code Playgroud)
我想我需要一个格式提供程序来消磨时间.
如何启动Outlook电子邮件窗口(类似于mailto:在超链接中执行的操作)?
这需要在LinkButton单击事件中完成.
在C#中使用ASP.NET MVC显示相对日期(例如:20分钟前)的最佳库是什么?
我有一个Windows aspx表单,我有一个TextBox,Button和一个GridView.将TextBox被存储为变量@subschedule并传递到一个存储过程.我想做的是将该程序的结果填充到我的程序中GridView.有谁能建议这样做的方法?
谢谢
我在页面中使用了'n'个服务器控件.现在我正在进行性能调整,我注意到我ViewState太大了,这让我的页面变慢了.
我知道ViewStateGzip可以压缩大小.ViewState在asp.net中减少任何其他建议.我不想在IIS中执行,因为我的Web应用程序托管在共享服务器上.
我有一个DataSet,我想转换DataSet成List<T>
T型对象
如何转换我的DataSet?它有10列,我的对象拥有所有10个属性,它返回超过15000行.我想将该数据集返回List<obj>并循环它我该怎么做?
我正在尝试为mysql编写一个自定义的用户定义函数,所以我以http://www.mysqludf.org/index.php中的str_ucwords函数为例来构建我自己的函数.
my_bool str_ucwords_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
/* make sure user has provided exactly one string argument */
if (args->arg_count != 1 || args->arg_type[0] != STRING_RESULT || args->args[0] == NULL)
{
strcpy(message,"str_ucwords requires one string argument");
return 1;
}
/* str_ucwords() will not be returning null */
initid->maybe_null=0;
return 0;
}
char *str_ucwords(UDF_INIT *initid, UDF_ARGS *args,
char *result, unsigned long *res_length,
char *null_value, char *error)
{
int i;
int new_word = 0;
// copy the argument …Run Code Online (Sandbox Code Playgroud) 如何Button在使用javascript更改属性值后检索自定义属性?
例:
Asp文件
<asp:Button ID="Button1" runat="server" Text="Button1" />
<asp:Button ID="Button2" runat="server" Text="Button2" OnClick="Button2_Click" />
<script type="text/javascript">
var btn1 = '#<% Button1.ClientID %>';
var btn2 = '#<% Button2.ClientID %>';
$(btn1).click(function(e) {
e.preventDefault();
$(btn2).attr("actIndex", "2");
});
</script>
Run Code Online (Sandbox Code Playgroud)
CodeBehind文件
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
Button2.Attributes.Add("actIndex","1");
}
protected void Button2_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
// this should be 2 if button1 has been clicked
string actIndex = btn.Attributes["actIndex"];
}
Run Code Online (Sandbox Code Playgroud)
如果我单击Button1然后单击Button2该actIndex …
c# ×5
asp.net ×4
linq ×2
.net ×1
.net-3.5 ×1
asp.net-mvc ×1
c ×1
controls ×1
data-binding ×1
dataset ×1
date ×1
formatting ×1
gridview ×1
javascript ×1
join ×1
linkbutton ×1
linq-to-sql ×1
linqpad ×1
mysql ×1
optimization ×1
performance ×1
postback ×1
scalability ×1
sql ×1
sql-server ×1
timespan ×1
viewstate ×1