Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6175923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:00:31+00:00 2026-05-24T00:00:31+00:00

I have an extension method defined like so: public static TSource MaxBy<TSource, TResult>(this IEnumerable<TSource>

  • 0

I have an extension method defined like so:

public static TSource MaxBy<TSource, TResult>(this IEnumerable<TSource> collection, Func<TSource, TResult> func) where TSource : class
{
    var comparer = Comparer<TSource>.Default;
    TSource maxItem = null;
    foreach (var item in collection)
    {
        if (comparer.Compare(item, maxItem) > 0)
            maxItem = item;
    }
    return maxItem;
}

which I then use in the following LINQ-to-Entities query:

var balancesQuery = from t in db.Transactions
                    where t.UserId == userId
                    group t by t.CurrencyCode into tg
                    let tMaxDate = tg.MaxBy(i => i.TsCreate)
                    join c in db.Currencies on tg.Key equals c.CurrencyCode
                    select new { Currency = c, Balance = tMaxDate.Balance }

So what I’m doing is – get the newest transaction (MaxBy TsCreate) in each currency (group by CurrencyCode) and then select the balance against each of those transactions.

My problem is – this does not work with Entity Framework (LINQ-to-Entities; I get:

LINQ to Entities does not recognize the method ‘Transaction MaxBy[Transaction,DateTime](System.Collections.Generic.IEnumerable'[Transaction], System.Func’2[Transaction,System.DateTime])’ method, and this method cannot be translated into a store expression.

The same query works with LINQ to SQL.

My questions are:

  1. Is there a way to make it work with Entity Framework?
  2. Or maybe there is a better way of querying for the same information, which would work with Entity Framework?

Thanks in advance for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:00:32+00:00Added an answer on May 24, 2026 at 12:00 am

    Isn’t the query same as:

    var balancesQuery = from t in db.Transactions
                        where t.UserId == userId
                        group t by t.CurrencyCode into tg
                        join c in db.Currencies on tg.Key equals c.CurrencyCode
                        select new { 
                            Currency = c, 
                            Balance = tg.OrderByDescending(i => i.TsCreate).Take(1).Balance 
                        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined an extension method in app_code like below. public static class Extensions
/*I have defined Extension Methods for the TypeX like this*/ public static Int32 GetValueAsInt(this
Does Python have extension methods like C#? Is it possible to call a method
I would like to create a safe sum extension method that would have the
I have the following base abstract class defined as: public abstract class BaseObject<T> :
I have an extension method on the HttpApplicationState object for getting my IoC container
I have a simple extension method on the int type so I can do
I have a class library with some extension methods written in C# and an
I have an extension method to dynamically filter Linq to Entities results using string
I need some help creating this extension method. My view inherits from <%@ Page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.