score:3
Accepted answer
try this, assuming your entities are db.foodiate
and db.foodinfridge
(loving the table names!):
var food = (from fif in db.foodinfridge
join fia in db.foodiate on fif.food equals fia.food
select new
{
food = fif.food,
category = fif.category,
date = fia.date
})
.orderbydescending(f => f.date)
.tolist()
that way you have the food in order of date eaten, most recent first. then if you want the top three of them, you can do (make sure you check that the food list is longer/same size as the number you are taking though, otherwise it'll die!):
var topfood = food.take(3).tolist();
Source: stackoverflow.com
Related Query
- Latest records of each type?
- LINQ for getting the 5 latest records for each distinct name
- get only latest items for each id type
- Select latest 'N' records on the right table for each record on left table of left join on linq to sql
- Linq: dynamic Where clause inside a nested subquery get latest records of each group
- Get record for each type with latest / bigger dates in C# DBML
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet'
- Linq to select latest records
- This code returns distinct values. However, what I want is to return a strongly typed collection as opposed to an anonymous type
- LINQ with subselect and groupby to get only the latest version of each item in a list
- LINQ Source Code Available
- C# LINQ query (MYSQL EF) - Distinct and Latest Records
- .NET 4 Code Contracts: "requires unproven: source != null"
- Cannot convert source type to target type List<KeyValuePair> Linq
- Entity Framework select most recent record for each type of record
- The given value of type String from the data source cannot be converted to type int of the specified target column
- Query to retrieve the latest status of each action
- Avoid extra loop and could not find implementation of query pattern for source type int Select not found
- LINQ In Clause With Group By And TOP N Records Within Each Group
- Query expressions over source type 'dynamic' or with a join sequence of type 'dynamic' are not allowed
- Why not reveal the type and identity of the source to the client?
- Cannot convert source type system.nullable to target type int
- Could not find an implementation of the query pattern for source type
- creating Linq to sqlite dbml from DbLinq source code
- LINQ Get Latest Record from Multiple Records to List
- How can i copy data table records of different field name based on mapping list evaluating condition on source data table?
- code first approach error: the specified type member 'yyyxx' is not supported in linq to entities
- Create a class type in code in .net c#
- Anonymous type with counter for each result
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet` 'Where' not found
More Query from same tag
- Linq to SQL Delete/Add Child objects
- MVC how to pre-populate IEnumerable<string> before attempting to populate with LINQ results
- LINQ to Entities does not recognize the method 'Int32 IndexOf(Int32)'
- How to find the first occurrence of a substring in a list of substrings?
- how to get the value using linq query C#
- LINQ Query to count only certain values
- LINQ optimization using single query on collection of integers
- Linq: let statement as a constant?
- parse XDocument for attributes
- LINQ XML Document
- Linq nested list expression
- Can't build lambda Expression with unknown type of a property
- How to use a LINQ : If there are several min and max values, just remove only one min and max value in List
- insert two object in database with linq
- Grouping list items by class property proximity from each other with some threshold
- Match on 2 values
- Make access possible to dynamic table LINQ EF6 Code First
- Convert SQL to Linq where there is in clause
- Concatenating two sequences with their elements interleaved
- operator '&&' cannot be applied to operands of type 'int' and 'bool' linq
- distinct in the two list
- Input array is longer
- FInd Previous nodes in a Tree in C#
- Linq Func/Expression Local Evaluation
- Items with both properties contained in a list
- How to query XML with the same element and attribute name using linq
- Expanding wildcards in a csv string to generate a collection of csv strings?
- LINQ lambda with where clause
- WPF VS2015 Accessing Datgrid cells when datagrid datacontext is query result
- LINQ retrieve values from a table that of which fields(of a certain column) are not equal of another table