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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:43:08+00:00 2026-06-04T12:43:08+00:00

Merging data from two lists conditionally table structure is as following MobileID ModelID ManufacturerID

  • 0

Merging data from two lists conditionally

table structure is as following

MobileID   ModelID   ManufacturerID    IsApproved

where IsApproved is boolean value,

When new mobile entry done in database, it goes for the approval to the manager, till that it’s IsApproved value is 0, when it gets approved IsApproved value will become 1.

I want to do as following

I am getting the list of all approved mobile using first query written below

now problem is I have to display all the mobiles based on 2 conditions

1) If a mobile exists with same modelID and manufacturerID (means the specification is updated) than it’s IsApproved field will become 0 –> not in DB but into the list for display purpose only)

2) If Mobile is new than it’s IsApproved status should be 0

What should I do to merge this two lists conditionally?

My LINQ queries are as below

var listApproved = objMobile.MobileLists.where(mb => mb.IsApproved == true).toList();
var listUnApproved = objMobile.MobileLists.where(mb => mb.IsApproved == false).toList();

Suppose table data is as following

MobileID    ModelID     ManufacturerID     IsApproved
01            mod1             manu1               1
02            mod2             manu2               1
03            mod3             manu3               1
04            mod1             manu1               0
05            mod5             manu5               0
06            mod6             manu6               0
07            mod2             manu2               0

I Want the list as

MobileID    ModelID     ManufacturerID     IsApproved
01            mod1            manu1            0
02            mod2            manu2            0
03            mod3            manu3            1
05            mod5            manu5            0
05            mod6            manu6            0
  • 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-04T12:43:09+00:00Added an answer on June 4, 2026 at 12:43 pm

    Well, first let’s cache your list in memory to save us getting it more than once:

    var listOfAllMobiles = objMobile.MobileLists.ToList();
    

    Now let’s do your logic to get all the mobiles:

    var mobileList = listOfAllMobiles
        .Select(m => new Mobile
                     {
                         IsApproved = m.IsApproved == true && !listOfAllMobiles
                             .Any(l => l.ModelID == m.ModelID
                                 && l.ManufacturerID == m.ManufacturerID
                                 && l.MobileID != m.MobileID),
                         MobileID = m.MobileID,
                         ModelID = m.ModelID,
                         ManufacturerID = m.ManufacturerID
                     })
        .ToList();
    

    EDIT: The above code will set the correct values, but it won’t filter out the mobiles with the duplicate ManufacturerId and ModelID. You’ll have to use an additional foreach for that, like so:

    var displayMobileList = new List<Mobile>();
    
    foreach(var mobile in mobileList
        .Where(m => !displayMobileList
            .Any(m2 => m2.ModelID == m.ModelID 
                && m2.ManufacturerID == m.ManufacturerID)))
    {
        displayMobileList.Add(mobile);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am merging two tables, each one with different events data. Each table has
AFAIK, there are two ways of passing data to the view from controller :
I'm trying to merge two file that have the same structure, and some data
I have two MySQL databases with identical table structure, each populated with several thousand
It is connected to BI and merging of data from different data sources and
Most of the questions about merging data.frame in lists on SO don't quite relate
I am having issues with ADO.NET 2.0 merging/importing data. I need to update/insert data
We use spark to generate HTML-mails. When merging our data into the template I
I've just finished merging two branches that have been separated for a long time,
I am trying to merge two list in parallel. I have two sorted lists

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.