How to compare tow list of object ? RRS feed

  • Question

  • User632428103 posted

    Hello all,

    imagine this scenario, i have a device when the user connect i call a web service and get some resutl


    i insert all content into the database all works fine.

    Now, we add in the back end some new object, modify, update, delete and so on ...

    user make a log off, when user connect again i call again the web service and get the new IEnumerable<someObject>

    I would like to know i can make a find the DIFFERENCE between these two objects ?

    because i need to insert some news, and delete some old ...

    I've try that, but that's work only if i have some new object IN the wsDatas

    //a: get datas from db
                        var dbDatas = from db in xxx.SelectAll<someObject(true)
                                      select new { db.ProfileCode, db.ProductCode, db.CategoryCode, db.OptionCode };
    //b: get data from web service
                        var wsDatas = from ws in datas
                                      select new { ws.ProfileCode, ws.ProductCode, ws.CategoryCode, ws.OptionCode };
                        // compare
                        var newDatas = wsDatas.Except(dbDatas);

    of course, i can delete all datas and replace all but i would like to know how to find difference between two list of objects

    thanks in advance

    Thursday, January 25, 2018 8:20 AM

All replies

  • User-832373396 posted

    <g class="gr_ gr_15 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="15" data-gr-id="15">Hi</g> <g class="gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="5" data-gr-id="5">jimmy</g>,

    Sir, If you only want to compare two <g class="gr_ gr_55 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="55" data-gr-id="55">list</g> of object.


    This is the way.

    and in fact, it is very strange with your logic.

    • 1 What represents the old and what represents the new?
    • 2 if you already added or modified to the database, then when you get the data from web service,  it should be the updated data.

    So they are same, no difference;

    • 3 maybe you could show us the data for help you better;

    insert some news, and delete some old ...

    • 4 is it means that to insert some news into the database?

    With regards, Angelina Jolie

    Friday, January 26, 2018 8:18 AM