小编Rad*_*u D的帖子

.NET LINQ查询语法与方法链

以下两个陈述之间是否有任何性能差异?

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语法和方法链之间是否有任何性能差异?

.net linq performance

41
推荐指数
1
解决办法
6716
查看次数

如何在LINQ查询语言中使用where/index?

是否有可能使用查询语言编写此...而不是方法链?

 notifications.Where((n, index) => n.EventId == m_lastSelectedEventID)
              .Select((n, index) => new {Position = index}).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)

谢谢,拉杜

.net c# linq

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

检测是否处置了控制

在我的应用程序中,我有一个用户控件,使用线程池执行异步操作.线程池方法如下所示:

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.

你知道一种检测对话框是否处理的方法吗?我不想在关闭时设置对话框设置的控件属性.还有另一种解决方法吗?

谢谢,

拉杜

.net c# winforms

14
推荐指数
2
解决办法
7467
查看次数

App.config连接字符串相对路径

我需要在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)

那可能吗?

.net sqlite configuration connection-string app-config

14
推荐指数
3
解决办法
3万
查看次数

如果参数为null,则where where语句中的TSQL Case

我有一个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

sql t-sql sql-server

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

如何在C#中获取枚举的小写表示?

enum在ASP.NET MVC应用程序中有以下内容,我想将该枚举用作参数.为此,我想返回它的小写字符串表示enum.

 public enum SortOrder
 {
      Newest = 0,
      Rating = 1, 
      Relevance = 2 
 }
Run Code Online (Sandbox Code Playgroud)

如何在C#中获取枚举的小写表示?我想让enums保留他们的天然标题表示.

.net c# enums

9
推荐指数
1
解决办法
6592
查看次数

用于支持多种语言的ASP MVC技术

我想制作一个支持多种语言的网络应用程序(英语,德语,法语......)我还想检测默认使用的浏览器语言,并让用户选择语言.

这样做的最佳方法是什么?

  1. 为每种语言设置单独的视图.将语言保留在用户的会话中并呈现正确的视图.
  2. 要在DB中进行字符串转换,并在每次渲染视图时使用自定义机制进行转换.
  3. MVC是否有一些本机支持?
  4. 其他选择?

谢谢,

拉杜

asp.net-mvc web-applications internationalization

8
推荐指数
1
解决办法
4173
查看次数

SoapHttpClientProtocol日志响应xml

几天我们的应用程序出现问题.我们使用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?任何帮助或想法都非常受欢迎.

c# web-services soaphttpclientprotocol webservice-client

8
推荐指数
1
解决办法
7794
查看次数

如何在使用Membership时测试ASP.NET MVC 3身份验证

我想测试我的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)

c# asp.net asp.net-mvc unit-testing

8
推荐指数
1
解决办法
2815
查看次数

从另一个表中的数据更新计数列

在我的数据库中我有两个表项(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)

sql-server stored-procedures

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