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 8532051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:37:30+00:00 2026-06-11T09:37:30+00:00

Can I restructure the following into a more compact linq query, ideally without the

  • 0

Can I restructure the following into a more compact linq query, ideally without the introduction of a helper function?

var revPerUnitChanges = 
    from row in this.DataTable.GetChanges(DataRowState.Modified).AsEnumerable()
    let field = "Rev/Unit"
    select new {
        Field = field,
        From = row.Field<decimal>(field, DataRowVersion.Original),
        To = row.Field<decimal>(field, DataRowVersion.Current),
        ItemIds = row.Field<string>("ItemIds"),};
var costPerUnitChanges = 
    from row in this.DataTable.GetChanges(DataRowState.Modified).AsEnumerable()
    let field = "Cost/Unit"
    select new {
        Field = field,
        From = row.Field<decimal>(field, DataRowVersion.Original),
        To = row.Field<decimal>(field, DataRowVersion.Current),
        ItemIds = row.Field<string>("ItemIds"), };
var numUnitsChanges = 
    from row in this.DataTable.GetChanges(DataRowState.Modified).AsEnumerable()
    let field = "Units"
    select new {
        Field = field,
        From = row.Field<decimal>(field, DataRowVersion.Original),
        To = row.Field<decimal>(field, DataRowVersion.Current),
        ItemIds = row.Field<string>("ItemIds"), };
var changes = 
    revPerUnitChanges
        .Concat(costPerUnitChanges
        .Concat(numUnitsChanges))
        .Where(c => c.From != c.To);
  • 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-11T09:37:31+00:00Added an answer on June 11, 2026 at 9:37 am

    Start out by creating a helper class to hold onto the data. (Your code doesn’t have any problems using anonymous types, but if you want to refactor sections into methods it’ll be much easier with a named class.)

    public class MyClass //TODO give better name
    {
        public MyClass(DataRow row, string field) //You could have a public static generate method if it doesn't make sense for this to be a constructor.
        {
            Field = field;
            From = row.Field<decimal>(field, DataRowVersion.Original);
            To = row.Field<decimal>(field, DataRowVersion.Current);
            ItemIds = row.Field<string>("ItemIds");
        }
        public string Field { get; set; }
        public decimal From { get; set; }
        public decimal To { get; set; }
        public string ItemIds { get; set; }
    }
    

    Now that we have that out of the way the query is fairly straightforward.

    var changes = dataTable.GetChanges(DataRowState.Modified)
        .AsEnumerable()
        .Select(row => new[]{ //create 3 new items for each row
                        new MyClass(row, "Rev/Unit"),
                        new MyClass(row, "Cost/Unit"),
                        new MyClass(row, "Units"),
                    })
        .SelectMany(item => item) //flatten the inner array
        .Where(item => item.From != item.To);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can any one tell, how to get the result of LINQ query contains group
I can create the following and reference it using area[0].states[0] area[0].cities[0] var area =
Can someone thoroughly explain the last line of the following code: def myMethod(self): #
Can I be sure about the order in a Python dictionary? The function op.GetTangent(id)
I'm trying to use the following query syntax from a php file: $sql =
I have the following mysql query which is taking about 3 minutes to run.
I have a query like so. var query = from o in _context.Orders join
How can I use color with ReStructured Text? For example, **hello** translates into <strong>hello</strong>
I'm working on a solr query similar to the following: ((myField:superneat AND myOtherField:somethingElse) OR
I'm aggregating data from one table into another using a query similar to these:

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.