Intersect does not retrieve list as expected

65 views Asked by At

I have two lists, the first one contains a lot of items, and the second one contains one item that also exists on first list.

And I was wrote code to check if the first list contains all second list items and retrieve Boolean value.

My issue is the Intersect retrieve empty list which means there's no intersect between two lists that I compare (so the value will be false always).

My code line:

var res = retrieved.ResponeDataList.Intersect(listOrObj.ResponeDataList).Count() == listOrObj.ResponeDataList.Count();

listOrObj.ResponeDataList contains one item with value:

"{{DapperRow, id = '1', name = 'testEntity', diagram_id = '1', creation_date = '1/27/2022 3:00:04 PM', created_by = '7', modification_date = '1/27/2022 1:04:06 PM', modified_by = '7', deletion_date = '1/27/2022 1:07:07 PM', deleted_by = '7', mapped_table = 'TE        '}}".

I was tried to get the value of the first object from both lists and fill them on testing lists and it's work fine as the following:

List<dynamic> a = new List<dynamic>();
a.Add("{{DapperRow, id = '1', name = 'testEntity', diagram_id = '1', creation_date = '1/27/2022 3:00:04 PM', created_by = '7', modification_date = '1/27/2022 1:04:06 PM', modified_by = '7', deletion_date = '1/27/2022 1:07:07 PM', deleted_by = '7', mapped_table = 'TE        '}}");
a.Add("{{DapperRow, id = '2', name = 'testEntity2', diagram_id = '5', creation_date = '1/27/2022 5:10:27 PM', created_by = '7', modification_date = '1/27/2022 1:04:06 PM', modified_by = '7', deletion_date = '1/27/2022 1:07:07 PM', deleted_by = '7', mapped_table = 'TE        '}}");
a.Add("{{DapperRow, id = '3', name = 'testEntity3', diagram_id = '110', creation_date = '1/27/2022 10:22:08 PM', created_by = '7', modification_date = '1/27/2022 1:04:06 PM', modified_by = '7', deletion_date = '1/27/2022 1:07:07 PM', deleted_by = '7', mapped_table = 'TE        '}}");
a.Add("{{DapperRow, id = '4', name = 'testEntity4', diagram_id = '72', creation_date = '1/27/2022 11:01:52 PM', created_by = '7', modification_date = '1/27/2022 1:04:06 PM', modified_by = '7', deletion_date = '1/27/2022 1:07:07 PM', deleted_by = '7', mapped_table = 'TE        '}}");
List<dynamic> b = new List<dynamic>();
b.Add("{{DapperRow, id = '1', name = 'testEntity', diagram_id = '1', creation_date = '1/27/2022 3:00:04 PM', created_by = '7', modification_date = '1/27/2022 1:04:06 PM', modified_by = '7', deletion_date = '1/27/2022 1:07:07 PM', deleted_by = '7', mapped_table = 'TE        '}}");
var rr = a.Intersect(b).Count() == b.Count(); //value = true

Any help?

EDIT: For test I tried to add range from second list to the first list and the Intersect worked for new added items only, Although the added items already exists before on the first list.

retrieved.ResponeDataList.AddRange(listOrObj.ResponeDataList);
var res = retrieved.ResponeDataList.Intersect(listOrObj.ResponeDataList).Count() == listOrObj.ResponeDataList.Count();

both lists type is List<dynamic> and I'm sure that the all items in second list already exists in first list before try to add range.

0

There are 0 answers