Lambda Expression Is Slower Than Foreach Statement?

Mar 23, 2011

I did a small experiment to test whether lamdba expression can retrieve faster results than foreach statement. but, Lambda failed

[Code]....

why lambda is slower than foreach. This may be a drawback of lambda expression

View 3 Replies


Similar Messages:

ADO.NET :: Does Lambda Have An IN Expression That Works Like Sql

Feb 6, 2011

I have a dictionary with integers representing ProductId's.

I want to get all the Products that are listed in this dictionary. What is the best way of doing this?

I have tried the following which doesnt work:

gvBasket.DataSource = ent.Products.Where(x => x.ProductId in Dic.Keys);

View 9 Replies

MVC :: RenderAction With Lambda Expression In MVC 3.0 Preview 1

Sep 29, 2010

i have the following, which works:

@{Html.RenderAction("Detail", "Help", new { pageName = "press" });}
But instead i'd like to use a lambda expression to get away from the string bits. I tried using the following (which is the nearest approximation i could figure based on my limited knowledge of the engine):

@{Html.RenderAction<HelpController>(x => x.Detail("press"));}
But i get the following error:

The non-generic method 'System.Web.Mvc.Html.ChildActionExtensions.RenderAction(System.Web.Mvc.HtmlHelper, string, string, System.Web.Routing.RouteValueDictionary)' cannot be used with type arguments

However, i'm reading in the Apress MVC 2.0 book that it is in fact declared as a method that takes type arguments. Am i missing an assembly reference, or has it not been included in the MVC 3.0 Preview 1 build?

View 3 Replies

How To Update List Using Lambda Expression

Mar 15, 2011

I have two lists. lst contains ViewState Data i.e All the records of the gridview & second lstRank contains the list of integer(i.e ID) for only those records which are marked as checked (i.e Gridview contains a columns for checkbox). Now i want to update the lst bool status depending upon integer ID of lstRank. How it can be achieved by lambda expression

List<Tuple<int, string, bool>> lst = (List<Tuple<int, string,bool>>)ViewState["gvData"];
List<int> lstRank = gvDetails.Rows.OfType<GridViewRow>().Where(s => ((CheckBox)s.FindControl("chkSelect")).Checked)
.Select(s => Convert.ToInt32(((Label)s.FindControl("lblRankCD")).Text)).ToList();

View 1 Replies

ADO.NET :: How To Create A Generic Lambda Expression

Oct 26, 2010

I Use entity framework 4.

Here is my model

Language
LangID
LangName
Product
PrdID
IsActive
ProductText
PrdID
LangID
Text
Category
CatID
IsActive
CategoryText
CatID
LangID
Text

Each time I want the text for one of these model, I execute this lambda expression p=> p.LangID == 1

Is it possible to create a generic lambda expression function that all of these model can use.?

View 1 Replies

C# - How To Convert Lambda Expression Output To List

Mar 14, 2011

I am selecting the checked rows from Gridview. To achieve this i have written a lambda expression using dynamic keyword.

var dn = gvLoans.Rows.OfType<dynamic>().Where(s => s.FindControl("chkSelect").Checked == true).Select(s => s.FindControl("lblCD")).ToList();

I want the output of this in List. Can it be achieved by extending the query or i have to write foreach statement.

View 2 Replies

C# - How To Use Lambda Expression To Select Different Fields From Field Names

Nov 18, 2010

I need to get two fields from a database table (retrieved using linq-to-sql), one field is a datetime (and is a fixed field) and the other is always a decimal, but the field can be different.

The table holds currency data which is processed twice a day and in different currencies so could have fields such as AM_USD, PM_USD, AM_EUR etc. And I need to get data such as a list of the date against PM_USD or the date against AM_EUR.

I would like to be able to call the data using a lambda expression for example (this is a stripped out example):

data = TableData.Select(x=>new {x.DateTimeAdded, x.[**field name as string**]});

I have been trying to write a function to do this, and am failing dismally.

The closest I have managed is:

private Func<TableData, KeyValuePair<DateTime, decimal>> CreateSelect(string FieldName)
{
var parameterExp = Expression.Parameter(typeof(TableData), "sel");
var dateParameter = Expression.Parameter(typeof(DateTime), "DateTimeAdded");
var fieldParameter = Expression.Parameter(typeof(decimal), FieldName);
ConstructorInfo constructorInfo = typeof(KeyValuePair<DateTime, decimal>).GetConstructor(new[] { typeof(DateTime), typeof(decimal) });
NewExpression constructExpression = Expression.New(constructorInfo, new ParameterExpression[] { dateParameter, fieldParameter});
var lambda = Expression.Lambda<Func<TableData, KeyValuePair<DateTime, decimal>>>( constructExpression, parameterExp);
return lambda.Compile();
}

Which fails with "System.InvalidOperationException: Lambda Parameter not in scope".

I'm sure I missing something obvious, or going about it wrong way.

View 2 Replies

ADO.NET :: Finding Lambda Expression Against Entity Framework Collection?

Aug 6, 2010

I'm new to LINQ and EF and I seem to be having trouble working this out.

I have a many-to-many relationship between my Location and Region tables. When adding or editing a Location, my interface allows the user to check any number of related Regions. If they click OK, I need to add any new relationships that were checked, and delete any existing relationships that have been unchecked. My basic code is shown below.

However, this code doesn't work. Lower down, the line location.Regions.Contains(region) returns false even when the location already is related to the region. The issue appears to be because the region is from my populated listbox that was initialized earlier and is no longer part of the current EF context. But if I try and add it, I get an error that there is already a Region with that ID.

It seems like what I want to do is change this line to something like location.Regions.Contains((r) => r.RgnID == region.RgnID) so I'm only testing for a particular ID. But this gives me the error "Cannot convert lambda expression to type 'TrailCalendar.Region' because it is not a delegate type."

I don't understand this error but, either way, I'm not sure how I can test if the relationship already exists without reloading a bunch of data, which I'd like to avoid.

View 1 Replies

C# - Pass Parameters To LINQ To XML Query By Using Lambda Expression?

Aug 17, 2010

I am new to LINQ to XML in .net(C#, asp.net). I want to know more about Lambda expressions. I am using Lambada expression with the following query.

count = FieldRoot.Element("USER").Element("MM")
.Descendants("MMMS")
.Where(a => a.Attribute("ID").Value == MID)
.SelectMany(b => b.Descendants("ABC")).Count();

how the Lambda expression work specially in case of parameters (in the above case a & b) ? What is the basic concept of parameters in Lambda expression ? Can we use the names of the variables defined outside of the query instead of a & b ? which elements a & b represent in the above case represent ? Can we pass parameters from outside in the query ? If we can pass parameters from outside query then how it will be done? If you give me any other example instead of the above query to understand the concept of parameter in Lambda expression.

View 1 Replies

DataSource Controls :: Equivalent Of Group Join In Lambda Expression?

Jun 29, 2010

What will be the equivalent GroupJoin lambda expression in LINQ when I do this.

Dim fruit_salad = (From fruits In _DataContext_Fruits _
Group Join fruitRipe In _DataContext_FruitRipe On fruitRipe.fID Equals fruits.fID Into Group
From fruitty_lecious In Group.DefaultIfEmpty() _

[code]...

View 5 Replies

Configuration :: Internet Explorer Gets Slower And Slower Untill Restart?

Sep 28, 2010

CWe've internal application written in ASP.NET, AJAX, SQL 2005. The problem is that sometimes response time (post back) is raising up to 10-30 second for some reson. The only way to make it faster is to restart browser (IE). Then it works really fast.

I have no clue what is causing this. Maybe it's viewstate, browser cache, browser memory clogging - I DON'T KNOW. The only thing I know is when I shut and reopen browser it's working fine. If I leave it open and come back in an hour or two it's really slow.

View 4 Replies

C# - Foreach Statement (get String Values)?

Jun 14, 2010

My code for splitting the strings is working however, i still need to use the splitted string my page. How can i achieve this? Here's my current code

private void SplitStrings()
{
List<string> listvalues = new List<string>();
listvalues = (List<string>)Session["mylist"];[code].....

how can i replace the response.write with any label or literal? when i tried to use a literal on the code it displays one single string not all of the strings that's been splitted.

View 3 Replies

DataSource Controls :: Foreach Like Statement In T-SQL?

Mar 10, 2010

how to do do some action recurting each row? My data looks like

[Column1] [Column2]
item 1 10
item 2 5

I would like to do something like..

foreach row in Column1 <-- how would I do this part??
While (row.Column2 > 0)
BEGIN
.. do something
row.Column2 = row.Column2-1
END

View 3 Replies

AJAX :: Application Getting Slower And Slower If Use More Time?

Jan 26, 2011

Our application is getting slower and slower if the user using more time... its start as regular website and works fine for some time..once the time is going on the speed getting slower..for one request it is taking more than 7 secs..

One of our Page (which is main one and user needs spent more time in this page) contains 3 formview and one grid view..all are inside 2 update panel and one main update panel.

[Code]....

View 4 Replies

C# - How To Show Label1.Text For Each Item In A Foreach Statement

May 9, 2010

I want to show each item Id that is doing now dynamically in a foreach statement.

But the following code only shows the last item Id in Label1.Text.

How to show Label1.Text for each item in a foreach statement?

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
.
protected void Button1_Click(object sender, EventArgs e)
{
List<int> list = new List<int>()
{
1,2,3,4,5
};
foreach (var item in list)
{
Label1.Text = string.Format("I'm doing item {0} now.", item.ToString());
Thread.Sleep(1 * 1000);
}
}

View 1 Replies

C# - Error - "Cannot Convert Lambda Expression To Type 'string' Because It Is Not A Delegate Type"

Jun 12, 2010

I get this error: "Cannot convert lambda expression to type 'string' because it is not a delegate type" - keyword select become underlined in blue.

[code]....

Above code should displays drop list of employees first name and last name in a combo box

View 2 Replies

SQL Server :: Regular Expression - Write SQL SELECT Statement To Determine If The Value In Table1?

Aug 18, 2010

I'm writing a SQL query where I need to detect if the value of an integer column in one table is contained within the value of a varchar column of another table. For example:


Table1 has columns A, B, C

A = 1

B = 2

C = 3

Table2 has columns D, E, F

D = "1,2,3,4,5"

E = "2, 5, 10, 15"

F = "1, 3, 49"

How would I write SQL SELECT statement to determine if the value in Table1.A is in Table2.D, Table1.B is in Table2.E, and Table1.C is in Table2.F?

View 7 Replies

SQL Server :: Incorrect Syntax Near The Keyword "with" - If Statement Is A Common Table Expression

Jan 19, 2011

i am writing storedprocedure for creating salary table ,but getting error while executing sp.

USE [Crystal.HRM]
GO
/****** Object: StoredProcedure [dbo].[Hrm_Salary] Script Date: 01/19/2011 13:11:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[Hrm_Salary](
@Pay_Basic char(1),
@Pay_Hra char(1)
)
AS
BEGIN
declare @fields nvarchar(max)
set @fields='Hrm_Emp_Id [int] not null'
if(@Pay_Basic='Y')
Begin
set @fields=@fields+', Pay_Basic [int] NOT NULL CONSTRAINT [DF_Hrm_Emp_Salary_Pay_Basic] DEFAULT ((0)),'
end
if(@Pay_Hra='Y')
Begin
set @fields=@fields+', Pay_Hra [smallint] NOT NULL CONSTRAINT [DF_Hrm_Emp_Salary_Pay_Hra] DEFAULT ((0)),'
End
set @fields=substring(@fields,0,len(@fields)-2)
declare @sql nvarchar(max)
set @sql='CREATE TABLE [dbo].[Salary]('+
@fields+'
CONSTRAINT [PK_Payroll] PRIMARY KEY CLUSTERED
(
[Pay_Emp_Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
USE [Crystal.HRM]
GO
ALTER TABLE [dbo].[Hrm_Emp_Salary] WITH CHECK ADD CONSTRAINT [FK_Hrm_Emp_Salary_Hrm_Emp_Tbl] FOREIGN KEY([Pay_Emp_Id])
REFERENCES [dbo].[Hrm_Emp_Tbl] ([Emp_Id])'
exec sp_ExecuteSql @sql
END

View 3 Replies

Mvc 2 Website Much Slower On IIS 7.5 Vs Built-in Server?

Jul 13, 2010

I am taking some time to learn how to develop asp.net mvc2 websites, but I'm used to working directly off IIS instead of the built-in web server that uses the random ports when you hit F5.

but I've noticed that using the built-in webserver, requests fly and are immediate. I am using only the default project with the Home and About pages as it comes out of the New ASP.NET MVC 2 Project settings, no database connections, nothing beyond the base install...

but when I setup the IIS website and pointed it to the same directory, each request takes at least 3-5 seconds to complete, sometimes more. this isn't just the "load" on the first request. EVERY request takes this long on IIS. but if I F5 and test the project once again, everything zips and the responses are immediate.

View 1 Replies

Is WPF Development Faster Or Slower Than Classic

Mar 30, 2011

Are you experienced with both ASP.NET and WPF coding? If so, I'll be grateful if you'll share your experience, We are estimating a 100-screen WPF project. Our estimation methodology involves characterizing the complexity of each screen. We then apply a standard number for the development time, based on the complexity and the technology. The standard number is based on the developer being good, not a super-star.

For example, here's a screen:

[Code]....

View 3 Replies

IIS7 Integrated Pipeline Mode Slower Than Classic?

Sep 20, 2010

we are running a complex 64-bit ASP.NET 2.0 application on W2008 R2 Standard and stress tests done with VS2008 Team System have indicated that integrated pipeline mode is 30% slower than classic mode.

We have compared the application traces extensively and it appears that integrated mode is uniformly slower than classic. That is, there is no single point that causes delays in integrated mode.

This is quite the opposite to everything Microsoft says about the integrated pipeline, so it might be that there is something quite wrong with the configuration of the integrated mode or the server. But we have not found any settings that would have any effect on this. Some complaints that Sharepoint and reporting services are slower in integrated mode can be found, but our application does not use them so this is quite likely unrelated.

View 2 Replies

DataSource Controls :: Much Slower Linq Query Than Optimised Sql ?

Feb 19, 2010

Slow query.Much slower linq query than optimised sql ?

View 1 Replies

Trying To Increase Speed - Using Classes That Aren't Necessary, Cause A Page To Load Slower?

Nov 26, 2010

I've been using things like Firebug and YSlow, so I'm not really looking for advice on increasing page load speeds, but I'm wondering does extra imports or using, especially if your importing or using classes that aren't necessary, cause a page to load slower?

View 2 Replies

C# - Setting Trust Level To High In Web.config Makes Application Run Slower?

Jan 11, 2011

We had a UAT and Production version of a .NET web application. UAT was taking around 5 seconds to run a particular operation while Prod was taking 35+ seconds.

This even happened when pointing both web applications at the same database and putting them both on the same machine.

The culprit was finally found to be the following entry, which was in the Prod but not UAT web.config

<trust level="High" originUrl="" />

why this would cause such a significant performance degradation??

View 1 Replies

Lambda Check For Null?

Mar 29, 2011

var pq = attributes.SingleOrDefault(a => a.AttributeName == PasswordQuestion").AttributeValue;

The above code will throw an error if null. What is the best way to handle this?The below code would work, but I can't help but feel there's a more graceful way?

var pq = (attributes.SingleOrDefault(a => a.AttributeName == "PasswordQuestion") != null) ? attributes.SingleOrDefault(a => a.AttributeName == "PasswordQuestion").AttributeValue : null;

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved