0

I have a list a analysts. Each analyst has a list of sector

public class Analyst : EntityNamed
{
  List<Sector> sectors;
}

public class Sector: EntityNamed
{
  List<Analyst> Analysts;
}

 // I'm using a WCF service to get all the analyst :

public List<Analyst> GetAnalyts()
{
 DataSet ds = EServiceClient.GetAnalysts();
 foreach (DataRow row in ds.Tables[0].Rows)  {
           var analyst = new Analyst()
            {
                  Name = row[1].ToString(),
                  LastName = row[2].ToString(),
                  PhoneNumber = row[3].ToString(),
                  Email = row[4].ToString()
           };
    }

//do something to prevent duplication of secotrs
}

The sectors are differentiate by their name

how can i do that without duplicating sectors in data Base ?

Thanks

Bilel Chaouadi
  • 903
  • 1
  • 10
  • 28

1 Answers1

0

You can prevent by using a Dictionary
Normally Dictionary < Key,Value > just support prevention for Same Key

But as far as I considered , you don't want any match. I mean 1-2 and 2-1 are the same record for you. So you can implement a hash table for this purpose

Hashtable with MultiDimensional Key in C#

I think, by overriding GetHashCode, Equals methods you will attain your goal.

Hope helps and hope I got the question right.

Community
  • 1
  • 1
Davut Gürbüz
  • 5,526
  • 4
  • 47
  • 83