Questions tagged [linq-extensions]
25 questions
12
votes
4 answers
Will First() perform the OrderBy()?
Is there any difference in (asymptotic) performance between
var a = Orders.OrderBy(order => order.Date).First()
and
var y = Orders.Where(order => order.Date == Orders.Min(x => x.Date)).ToList();
i.e. will First() perform the OrderBy()? I'm…

Martin
- 2,956
- 7
- 30
- 59
8
votes
4 answers
linq extension method to take elements from the end of the sequence
There is the enumerable extension method
Take(
IEnumerable source,
int count
)
which takes the first count elements from the start.
Is there a way to take the elements from the end?
or even better a way to take the…

Fabiano
- 5,124
- 6
- 42
- 69
4
votes
1 answer
Nullable values on LINQ search of jqGrid
first of all, sorry for my bad english, isnt my native language.
Im using jqgrid on a ASP.NET MVC project on my work, and have some problems when implement search.
Im try to use one solution that find on internet using LinqExtensions. The problem…

rdarioduarte
- 1,929
- 2
- 21
- 29
4
votes
4 answers
Expression.Equal - How to Compare Nullable and Non Nullable fields?
I have a nullable datetime field and I have to convert the string date field to a nullable datetime type (using Expression)....I did this using the below.
Expression.Constant(Convert.ChangeType(value,…

user2325247
- 774
- 1
- 7
- 18
3
votes
3 answers
Visual Studio doesn't show Linq extensions in my Asp.net MVC views
This baffles me and I can't seem to make Visual Studio 2010 to recognise System.Linq extension methods in view code. Intellisense doesn't work and Visual Studio red underlines unrecognised extension methods.
These are web.config's most relevant…

Robert Koritnik
- 103,639
- 52
- 277
- 404
2
votes
1 answer
Custom extension method for Linq To Entities
I'd like to make a query to my SQL Server 2008 R2 database using Linq-To-Entities.
I use Entity Framework 4.1 (Code-First)
the query has to compare the entities' hashed values with a paramater as follows:
myContext.Messages.Where(m =>…

Kamyar
- 18,639
- 9
- 97
- 171
2
votes
1 answer
Linq left join adding data to left object
I have 3 entities :
class Foo {
public Guid? BarId { get; set; } //Has optional bar
[NotMapped]
public boolean? HasXyzzy { get; set; }
}
class Bar {
...
}
class Xyzzy {
public Guid BarId { get; set; } //Always has Bar
}
I want to…

Vinzz
- 123
- 1
- 9
2
votes
2 answers
Can a LINQ extension method create a new KeyValuePair with a new() .Value when a Where clause isn't satisfied
I have a collection
List> x
where
public class Details
{
private int x;
private int y;
public Details()
{
x = 0;
y = 0;
}
...
}
I am using LINQ on my collection to return…

endorphin
- 656
- 2
- 6
- 15
2
votes
2 answers
IEnumerable extension methods (System.Linq) unavailable when inheriting from collection and implementing enumerable interfaces
Problem
If I have a class with a definition like this:
public class TestList : ObservableCollection, IList, ICollection, IEnumerable, IEnumerable
I cannot use the IEnumerable extension…

Alex
- 161
- 9
2
votes
1 answer
linq extension methods, how to update multiple properties of a single item?
In my database, I have a single item that I want to update. I tried doing something like this, but it doesn't work:
db.Items.Where(t => t.Id == itemId).Select(t =>
{
t.CurrentValue = 99;
t.TotalValue =…

ojek
- 9,680
- 21
- 71
- 110
1
vote
1 answer
LINQ Extensions not available inside CSharpCodeProvider
I have a .NET application that can take a script written in C# and executes it internally. The scripts are parsed by the class listed below and then compiled. I find that whenever I try and use System.Xml.Linq in the C# script that is compiled I get…

webworm
- 10,587
- 33
- 120
- 217
1
vote
2 answers
performance of linq extension method ElementAt
The MSDN library entry to Enumerable.ElementAt(TSource) Method says
"If the type of source implements
IList, that implementation is used
to obtain the element at the specified
index. Otherwise, this method obtains
the specified…

Fabiano
- 5,124
- 6
- 42
- 69
1
vote
0 answers
Using a Linq extension call inside another Linq extension call is throwing an exception
var tagByGroupIds = TagandTaggroupsservice.SelectAllQuery()
.Where(p => p.Tagid == i.TagId)
.Select(p => p.Taggroupid);
var tagGroups = Taggroupsservice.SelectAllQuery()
.Where(p =>…

Zein Sleiman
- 254
- 2
- 11
1
vote
1 answer
Combining two different PredicateBuilders with Expressions
I am having a predicate builder and it is working fine
var filter = sortKeys.Aggregate(filter, (currentFilter, sortkey) => currentFilter.Or(
x => x.Appointments.Any(y => y.RowStatus == Constants.CurrentRowStatus )));
I…

Rocky
- 139
- 12
1
vote
2 answers
Extending LINQ classes to my own partial classes in different namespaces?
I have a .dbml file which of course contains the auto-generated classes based on my tables.
I would however, like to extend them to my own classes. Typically I design such that each of my tables get their own namespace in their own folder containing…

SventoryMang
- 10,275
- 15
- 70
- 113