score:1
Accepted answer
FirstOrDefault/First/SingleOrDefault/Single accepts a predicate:
categoryId = dc.Categories.Single(c => c.Name == p.category).Id;
score:2
You need to use FirstOrDefault(), assuming you are getting valid, not null response from your webservice.
categoryId = Convert.ToInt32((from c in dc.Categories
where c.Name == p.category
select c.Id).FirstOrDefault()),
Source: stackoverflow.com
Related Articles
- Which LINQ query to select rows from 1 table that are not in another table
- How to include one specific row from another table with LINQ to Entities
- Efficient joining the most recent record from another table in Entity Framework Core
- Linq issue select Sum of one column minus another from different table
- creating Linq to sqlite dbml from DbLinq source code
- Update DataTable from another table with LINQ
- C# EF best way to lookup data from one table within another
- LINQ select from table where fieldValue is in another tables list of values
- LINQ Query to get data from another table
- LINQ query to return from one table based on matching another table
- using linq to get a single record from a table linked to another table
- Get ID from another table
- Datatable C# - How to get detail record from one table and its associated sub record from another table based on ID
- How do I filter db.table by another another column from another table in MVC 5?
- LINQ, select one item from one table, multiple items from another table
- LINQ retrieve values from a table that of which fields(of a certain column) are not equal of another table
- Get List ordered by number of records from another table using Linq
- How to return only rows where no rows from another table using Lambda Expressions in C#
- How to get One Table data on the basis of ID from another table
- Create column from another table dynamically
- Select values from one table based on specific value of another table Linq
- Group by one table and sum from another table in Linq
- LINQ query to retrieve from one table and then another
- LINQ to SQL to find values starting with characters from another table
- LINQ query for grouping a table based on the values from another table
- LinqtoSQL Getting a value from another table
- How can I add Sum from another Table in my Model?
- Get value of each comma separated ID from another table in Web Api-not working in live
- LINQ/lambda: How can I query a DB table based on information from another table? (many to many relationship)
- OrderBy with value from another table
- how can I see the inputs to a LINQ query?
- How to retrieve the particular X th position of node using xpath?
- List Iteration to Create Custom List in C#(Linq)
- Find duplicates between a list and a db table
- group by using anonymous type in Linq
- How to get required collection in my LINQ
- LINQ Recursive query in web api code
- Linq query with multiple subqueries
- Linq, How to select even where there is null in joined tables , C# windows form
- Why is Linq to Entities so slow the first time it's referenced
- How to serialize a raw json field?
- Returning the innerlist from a custom collection inheriting from List<T>
- linq query for getting largest time interval
- How to get my ViewModel instantiated
- Comparing and allocating elements in Linq
- LINQ merging multiple lists
- How to find the items that are repeated only once in the list using LINQ
- Why does EF lose include data when performing a "from" join
- Speeding up lookup of ranges of data from a collection
- Create a Groupedby HTML table using linq query