B
B
beduin012016-05-18 14:06:39
C++ / C#
beduin01, 2016-05-18 14:06:39

What is the best way to implement this loop in C#?

The situation is very simple.
I have a UserData structure. There fields id, guid, name and so on. I need to find a unique guid that is in the first database but not in the second.
Actually in the line:
if (GUIDListInTransitDB.Contains(el))
I need to check if there is a certain guide in the bulkhead. But how to do it?
I can't write:
if (GUIDListInTransitDB.Contains(el.guid))
in any case, the studio swears, which in general is logical.
How to be then? Is there a better solution and how to use this solution?

List<string> GUIDListExistsInTransitButNotInTargetDB; // ГУИДы которые есть в транзите, но нет в Target, с ними мы потом и будем работать
               List<UserData> GUIDListInTransitDB = TransitDbContext.GetGUIDList(11);
               List<UserData> GUIDListInTargetDB = TargetDbContext.GetGUIDList(11);

               foreach (var el in GUIDListInTargetDB)
            {
                if (GUIDListInTransitDB.Contains(el)) 
                    continue;
                else
                {
                  //  GUIDListExistsInTransitButNotInTargetDB.Add(el.Guid);
                }
            }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wkololo_4ever, 2016-05-18
@beduin01

if (GUIDListInTransitDB.Select(g=>g.ВАШЕ_ГУИД_СВОЙСТВО).Contains(el))

F
Fat Lorry, 2016-05-18
@Free_ze

I need to find a unique guid that is in the first database but not in the second.

Why not do it on the DB side? You can solve the problem with an elementary join.
Anyway, if you need set operations , why use dynamic arrays (List)?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question