以下两个陈述之间是否有任何性能差异?
from item in collection
where item.id == 3
select item
Run Code Online (Sandbox Code Playgroud)
和
collection.Where(item => item.id ==3)
Run Code Online (Sandbox Code Playgroud)
一般来说,LINQ语法和方法链之间是否有任何性能差异?
是否有可能使用查询语言编写此...而不是方法链?
notifications.Where((n, index) => n.EventId == m_lastSelectedEventID)
.Select((n, index) => new {Position = index}).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
谢谢,拉杜
在我的应用程序中,我有一个用户控件,使用线程池执行异步操作.线程池方法如下所示:
private void AsyncFunction(object state)
{
... do the calculation
//refresh the grid data on the UI thread
this.BeginInvoke(new MethodInvoker(() =>
{
... update the ui
}));
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果用户关闭对话框...用户控件被释放,我得到异常:
在创建窗口句柄之前,无法在控件上调用Invoke或BeginInvoke.
你知道一种检测对话框是否处理的方法吗?我不想在关闭时设置对话框设置的控件属性.还有另一种解决方法吗?
谢谢,
拉杜
我需要在app.config中设置sqlite连接字符串.我想设置相对于调试/发布文件夹的路径,数据库文件将被复制到这些文件夹.
<add name="EmailsSQLite" connectionString="data source=c:\Users\Test\Documents\Visual Studio 2008\Projects\TestConsole\Emails\data\EmailDatabase.sqlite" providerName="System.Data.SQLite"/>
Run Code Online (Sandbox Code Playgroud)
我希望有类似的东西:
<add name="EmailsSQLite" connectionString="data source=\data\EmailDatabase.sqlite" providerName="System.Data.SQLite"/>
Run Code Online (Sandbox Code Playgroud)
那可能吗?
我有一个SP给了我很多困难时期.
sp得到两个参数@madeByUserId和@reportedByUserId.我希望有类似的东西:
select * from table
where MadeByUserId = @madeByUserId (if(@reportedByUserID != null) and ReportedByUserID = @reportedByUserID)
Run Code Online (Sandbox Code Playgroud)
基本上我想在where子句中创建一个案例,以包含基于@reportedByUserId的null/not null状态的另一个过滤条件
那可能吗?
非常感谢,Radu
我enum
在ASP.NET MVC应用程序中有以下内容,我想将该枚举用作参数.为此,我想返回它的小写字符串表示enum
.
public enum SortOrder
{
Newest = 0,
Rating = 1,
Relevance = 2
}
Run Code Online (Sandbox Code Playgroud)
如何在C#中获取枚举的小写表示?我想让enums保留他们的天然标题表示.
我想制作一个支持多种语言的网络应用程序(英语,德语,法语......)我还想检测默认使用的浏览器语言,并让用户选择语言.
这样做的最佳方法是什么?
谢谢,
拉杜
几天我们的应用程序出现问题.我们使用SoapHttpClientProtocol来调用java mbeans.这基本上调用java webservice来调用方法.
我们的问题是,有时我们会得到以下异常:
XML文档中存在错误(1,172089).
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse上的System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,String encodingStyle)中的System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,String encodingStyle,XmlDeserializationEvents事件)处(位于JMXConnectorService.cs的DynamicMBeanResourceBinding.Invoke(OperationRequestType ManagedResourceOperation)中的System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,Object []参数)中的SoapClientMessage消息,WebResponse响应,Stream responseStream,Boolean asyncCall:JMXWSClient中的第781行连接\ Client.cs中的.InvokeMethodOnObject(String objectName,String methodName,ParameterType [] paramValue):第132行引起:发生了意外的文件结束.以下元素未关闭:图标
我们在通信层中的最后一个代码是:
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("soapHeaders", Direction = SoapHeaderDirection.In)]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://jsr262.dev.java.net/DynamicMBeanResource/Invoke", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute("ManagedResourceOperationResult", Namespace = "http://jsr262.dev.java.net/jmxconnector")]
public GenericValueType Invoke([System.Xml.Serialization.XmlElementAttribute(Namespace = "http://jsr262.dev.java.net/jmxconnector")] OperationRequestType ManagedResourceOperation)
{
object[] results = this.Invoke("Invoke", new object[] {ManagedResourceOperation});
return ((GenericValueType)(results[0]));
}
Run Code Online (Sandbox Code Playgroud)
在框架反序列化之前,有没有办法记录响应xml?任何帮助或想法都非常受欢迎.
我想测试我的AccountController
.问题是在Register方法中我使用下一行来创建用户:
Membership.CreateUser(model.Email, model.Password, model.Email, null, null, true, null, out createStatus);
Run Code Online (Sandbox Code Playgroud)
在Web应用程序中,我使用了CustomMembershipProvider
我使用web.config设置的内容.在我的单元测试中的会员级标准SqlMembershipProvider
.而不是我CustomMembershipProvider
在我的应用程序中使用的那些.
如何在单元测试环境中设置成员资格?我的意思是以编程方式设置它,因为asp net在读取web.config文件后设置它.
我已经使用接口来模拟用户管理数据层,但我在想是否有办法在这种情况下避免接口.能够在单元测试中设置成员资格的模拟实现.
public void RegisterTest()
{
IUsersManager repository = new Tests.Data.UsersManager();
AccountController target = new AccountController(repository);
//be able to set Membership underlying provider
Membership.Provider = new MockMembershipProvider();
}
Run Code Online (Sandbox Code Playgroud) 在我的数据库中我有两个表项(Id,...,ToatlViews int)和ItemViews(id,ItemId,Timestamp)
在ItemViews表中,我存储项目进入站点时的所有视图.我不时想调用存储过程来更新Items.ToatlViews字段.我尝试使用游标执行此SP ...但更新语句错误.你能帮我纠正一下吗?没有光标我可以这样做吗?
CREATE PROCEDURE UpdateItemsViews
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @currentItemId int
DECLARE @currentItemCursor CURSOR
SET @currentItemCursor = CURSOR FOR SELECT Id FROM dbo.Items
OPEN @currentItemCursor
FETCH NEXT FROM @currentItemCursor INTO @currentItemId
WHILE @@FETCH_STATUS = 0
BEGIN
Update dbo.Items set TotalViews = count(*)
from dbo.ItemViews where ItemId=@currentItemId
FETCH NEXT FROM @currentItemCursor INTO @currentItemId
END
END
GO
Run Code Online (Sandbox Code Playgroud) .net ×5
c# ×5
asp.net-mvc ×2
linq ×2
sql-server ×2
app-config ×1
asp.net ×1
enums ×1
performance ×1
sql ×1
sqlite ×1
t-sql ×1
unit-testing ×1
web-services ×1
winforms ×1