score:2
Accepted answer
You can use the indexed overload, but you need to use the LINQ to Objects version:
var query =
db.Table.Take(10).AsEnumreable()
.Select((t, index) => index == 0 ? t.Value1 : t.Value2);
score:1
If Table
have a primary key. You could do this:
var result= (
from t in db.Table.Take(10)
let first=db.Table.Take(10).Select (ta =>ta.PrimayKey).First()
select new
{
Value=(t.PrimaryKey=first?t.Value1 : t.Value2)
}
);
Source: stackoverflow.com
Related Articles
- Is it possible to detect if the selected item is the first in LINQ-to-SQL?
- Make access possible to dynamic table LINQ EF6 Code First
- Linq code to select one item
- Use Lambda or Linq to create Model of SelectList with Selected item for razor View in MVC5
- How to find the first item according to a specific ordering using LINQ in O(n)?
- Get first item in list from linq query
- Get the ordinal position while creating selected Item in a LINQ expression
- LINQ Source Code Available
- Is it possible to ignore a list item using the Skip method of the LINQ then apply skip on the list without losing that item?
- Linq with where clause in many-to-many EF Code First object
- LINQ How to combine second item in Tuple after query using where on first item
- creating Linq to sqlite dbml from DbLinq source code
- EF Code First - Linq to Entities Union EqualityComparer
- Linq sub query when using a repository pattern with EF code first
- SQL subquery result in LINQ and Entity Framework Code First
- Is it possible to do a Group By in LINQ but then only return the 'most recent' item (per group)?
- code first approach error: the specified type member 'yyyxx' is not supported in linq to entities
- Is it possible to use LINQ to detect duplicate adjacent characters?
- Using Linq lambdas, how can I get the first item in a two-key-sorted list?
- Is it possible to have one LINQ in one line of code for
- Retrieving property from first item with LINQ
- Code First EF: While searching database table is it possible to retrieve list of items it has in DataModel?
- How to handle nulls in this LINQ Code using a possible null List?
- LINQ to retrieve first matching item, or a blank value for each item in a list
- Linq query only returning first item of array
- source code for LINQ 101 samples
- LINQ obtaining first item not empty or null from Dictionary
- how to write a Linq query with a EF code first Many to Many relationship
- Selected item on SelectList going back to the first Item
- How do I use LINQ to return the first item from each set of Grouped data (In VB.Net)
- $ is not a function at b.$scope.SaveUser
- Where can I find the System.Linq.Dynamic dll?
- Building custom shaped view model for asp mvc framework
- Why is my function to filter files by User ID not filtering any files?
- multiple left joins with Linq
- Converting SQL Query in to Linq or in lambda
- Filter Data in observable collection based on the columns in datatable
- Linq how to use Where on the result of Join
- Join an IEnumerable in C# when the key selector shall return a set of keys
- Linq Query Return Error
- Adding ServiceStack OrmLite attributes in code instead of a property
- Linq to SQL nvarchar problem
- Attaching an object to another context in EF 4
- Why doesn't the Lookup that results from GroupBy have Lookup properties?
- RavenDb how do I reduce group values into collection in reduce final result?
- Not able to compare NAN using Expression
- Why does this work and this doesn't?
- Linq syntax for OrderBy with custom Comparer<T>
- CompilationErrorException when including System.Linq in Roslyn CP2
- Get the Value of XElements that dont has Child