tags:

views:

78

answers:

0

In my project I have about 10 Database and those 10 databases have 5 tables each. And in those tables I have two tables which almost have similar columns expect one column.

Right now I have two separate methods which update the data in these tables.

Is there any way I can combine this two method one.

 case "A":
     IEnumerable<ABClass> AResults = TFile.ProcessTextFileForA(language, country, tableName)
     db.Update_MC_A(language, country, AResults);
      break;  
 case "B":
      IEnumerable<ABClass> BResults = TFile.ProcessTextFileForB(language, country, tableName);
      db.Update_MC_B(language, country,BResults);
      break;

 Update_MC_A(string language, string country, IEnumerable<ABClass> AData)
    {

        switch (country)
        {
             case "GB":
                using (GBContext context = new GBContext())
                {
                    foreach (var item in AData)
                    {
                        context.Atables.InsertOnSubmit
                                       (new Atable
                                       {
                                       name = item.Name,
                                       address = item.Address,
                                       lang = language,
                                    // this is string and this is only different                                     column compar to B table (see below method)
                                    AID = item.VID
                                  });
                    }
                    context..SubmitChanges();
                }

                break;
              case "US":
                 using (USContext context = new USContext())
                 {
                      // Code as above ....
                 }
               break;

        }
    }

Update_MC_B(string language, string country,IEnumerable<ABClass> BData)
    {

        switch (country)
        {
             case "GB":
                using (GBContext context = new GBContext())
                {

                    foreach (var item in BData)
                    {
                        context.Btables.InsertOnSubmit
                                       (new Btable
                                       {
                                       name = item.Name,
                                       address = item.Address,
                                       lang = language,
                                       // this is string and this is only different column compar to V table 
                                       BID = item.VID

                                       }
                                       );
                    }
                    context..SubmitChanges();
                }

                break;
             case "US":
                 using (USContext context = new USContext())
                {
                          // code as above ....
                 }
                break;
        }
    }

Thanks