score:54
Accepted answer
Instead of Take(1)
which returns sequence IEnumerable<string>
, use FirstOrDefault()
which returns single string value (or null if there is no results). Also don't create anonymous type for subquery result:
imageName = (from soh in db.tblProductImages
where soh.product_id == e.ProductId
select soh.image_name).FirstOrDefault()
BTW FirstOrDefault()
generates TOP(1)
SQL.
Source: stackoverflow.com
Related Query
- Select top 1 result from subquery in linq to sql
- How to write linq query to match SQL like select top 100 * from tab?
- SQL subquery result in LINQ and Entity Framework Code First
- Stop LINQ to SQL from executing select statements after insert
- LINQ select Top 1 from List<T>
- c# Linq - Select Top 2 from Each Group
- C# Linq - how to select top 5 rows from a List<string> splitting on the first value
- creating Linq to sqlite dbml from DbLinq source code
- Getting single result from a query with anonymous types in Linq To Sql
- LINQ to SQL select distinct from multiple colums
- LINQ query translate from SQL which uses subquery containing GROUP BY and COUNT
- Linq to sql - Join 2 tables, select 1 row from right table with a 1 to many relationship
- How to determine size in bytes of a result set from LINQ to SQL
- How to Select top (5) contributors group by Business type code in c# linq query
- LINQ to SQL select exact matching record from many to many table
- LINQ to SQL - FROM X WHERE X = "1" SELECT Y
- Reading result from linq select query
- LINQ to SQL join two tables to select parent table twice based on two different columns from child table
- Select distinct and date difference in Linq to SQL from two dataTables
- Complex IEnumerable Result from LINQ Select
- With LINQ how do you return a string const in the result from the select operator
- how to select value from group by using linq to sql
- Getting Last rows from the result of Linq to Sql statement
- How to select top result for a given ID then join that into another table EF Core LINQ
- linq query to select top 3 from a group and get the average of those selected
- LINQ-to-SQL: Select mulitple properties from top row of each GROUP using LINQ query
- write linq similiar where in select from with inner join in sql query
- How can I select from a SQL DB using linq and EF where ExpiryDate is 30 days to expire from today using DateDiff function
- How to get top 4 result from a list using linq c#
- How can I select from an included entity in LINQ and get a flat list similar to a SQL Join would give?
More Query from same tag
- Apply IQueryable to another IQueryable / DbContext
- Linq Projection to DTO for Nested/Hierarchical Collections
- LinQ Sum Distinct Values Quantity and Total
- Error when trying to Find a record in a simple table with Linq to Entities
- Converting nested loop to LINQ statement
- left outer join after a inner join linq c#
- Fastest way to get the count of records per day between two dates
- LINQ to Entities does not recognize the method 'System.String ToString()'. Error happend when trying parse DateTime
- Using only the year part of a date for a WHERE condition
- Unique object counts are showing system text
- Left Outer Join in Linq to Entities / SQL
- Linq query for selecting an item from tree structure, but to look in the whole depth
- Sqlite PCL and Linq - Is SQLite.Net Table method loading the entire table into a collection?
- Using .net functions to filter Entity Framework information
- Remove 'duplicates' from a list of pairings
- Grouping in Linq with TimeSpan.Hours
- oData query in c#
- Entity Framework - Mapping doesn't map for stored procedure?
- What's better for creating distinct data structures: HashSet or Linq's Distinct()?
- C# LINQ to XML: "Safe" enum value from an XElement?
- It is possible to use LINQ in HtmlAgilityPack in C#?
- Linq query having group by
- Can I group-aggregate-calculate from another table directly in razor view?
- Linq to XML select descendent of descendant each with specific attribute
- Multiple filter LINQ search C#
- Remove row using linq
- Why doesn't XElement have a GetAttributeValue method?
- Use LINQ to get items in one List<>, that are not in another List<>
- how should I give the user a selection and grab the guid from that selection
- Create list of tuples with data from nested lists with Linq