In Entity framework, would the statement
MyDataContext.Products.OrderByDescending( (p) => p.Id ).GroupBy<Product,int>( (p) => p.ProductId ).Select( (g) => g.FirstOrDefault()).Where( (p) => p.Name.Equals("Something") );
result in another database query than
MyDataContext.Products.Where( (p) => p.Name.Equals("Something") ).OrderByDescending( (p) => p.Id ).GroupBy<Product,int>( (p) => p.ProductId ).Select( (g) => g.FirstOrDefault());
In other words, does the ordering of the calls to Where() and GroupBy() affect the final query to the db? Or is the entity framework smart enough to solve this?
The reason I wonder is that in the system I'm developing, we need to keep track of all changes to a product row. The solution we use in order to achieve this is to insert a new product row into the table rather than updating it. The different versions of a product is then grouped together by using the "ProductId"-field. Thus, I would like to move the "Grouping"-logic out to an external method, but still allow the caller to specify the Where-conditions...so my aim is to use the first approach.