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

  • SEARCH
  • Home
  • 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 8795895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:29:33+00:00 2026-06-13T23:29:33+00:00

I have an entity type, let’s call it Transaction, created by entity framework version

  • 0

I have an entity type, let’s call it Transaction, created by entity framework version 1. I have added the following property:

public partial class Transaction
{
    public int CurrentMaxRevisionNumber { get; set; }
}

And I have the following query:

public List<Transaction> GetTransactions(DateTime startDate, DateTime endDate)
{
   var query = from t in Repository.Transaction  
       let currentMaxRevisionNumber = 
        Repository.Transaction.Where(t1 => t1.TransactionId == t.TransactionId)
                               .Max(t1 => t.RevisionNumber)
       where t.StartDate >= startDate
             && t.EndDate < endDate)
    select t;

    return query.ToList();
}

The business rules for what we are trying to accomplish are the following:
– A new record for the transaction on the original date should be created with a code that indicates it has been soft deleted with an increased revision number.
– A new record for the transaction is to be created on the new date with an increased revision number.

The problem is that the process that determines when the transaction will be processed is done sequentially one day at a time and transactions are being moved from date to date and sometimes back to their original ones constantly. This may result that the max revision number of a given transaction will be the one from the specific date and not the max for the transaction. That is the reason why I am trying to do the “let” in the query.

Now the questions:
– How can I populate the CurrentMaxRevisionNumber property I created in the partial class with the query?
– Is there maybe another way I can accomplish this without having to do a query for each transaction since there may be several hundreds at any given date?

Thanks for you 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-06-13T23:29:34+00:00Added an answer on June 13, 2026 at 11:29 pm

    So the first thing I tried was to use the anti-pattern SELECT n + 1, which is a horrible solution but at least that showed us that by getting the correct data the problem would be fixed. It was something like:

    public List<Transaction> GetTransactions(DateTime startDate, DateTime endDate)
    {
       var list = (from t in Repository.Transaction  
           where t.StartDate >= startDate
                 && t.EndDate < endDate)
        select t).ToList();
    
        foreach(var item in list)
        {
            item.CurrentMaxRevisionNumber = Repository.Transaction.
                                            Where(t => t.TransactionId == item.TransactionId).
                                            Max(t => t.RevisionNumber);
        }
    
        return list;
    }
    

    For obvious reasons this solution was not acceptable so we came up with the following:

    public List<Transaction> GetTransactions(DateTime startDate, DateTime endDate)
    {
       var query = (from t in Repository.Transaction       
           where t.StartDate >= startDate
                 && t.EndDate < endDate)
        select new
        {
           OriginalTransaction = t,
           CurrentMaxRevisionNumber = Repository.Transaction.
                                            Where(t1 => t1.TransactionId == t.TransactionId).
                                            Max(t1 => t1.RevisionNumber);
        }).ToList();
    
        foreach(var item in list)
        {
           item.OriginalTransaction.CurrentMaxRevisionNumber = item.CurrentMaxRevisionNumber;
        }
    
        return list.Select(items => items.OriginalTransaction).ToList();
    }
    

    By using the anonymous object we can get all the data that we need in a single database access and the use the loop to populate the missing property.

    Since the liberty we had to modify the database and the application was somewhat limited, this solution proved to be the least invasive and more performant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a property of type uint on my entity. Something like: public class
I have a Web Service call that returns reporting data using Linq-To-Entity (strongly type
Let me explain my problem: I have four tables created as objects using Entity
I have 3 entities in my system. Let's call them entity A,B and C.
I'm starting to use Entity Framework. Let's say I have to Entity from my
Using this guide I have created a static library (let's call it AppCore )
Let's say we have the following simple model: public class Car { public int
One type of entity in my model (let's call it E1) needs to be
Let's say I have this basic string... string a = Entity; And this Type
I have the following entity inheritance, let's start with the root (it's just a

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.