public void mapExcel() { CropHendler m_CropHendler = new CropHendler(new GenericRepository <Crop>()); var filePath = @"C:\Users\user\Desktop\excel\rawData.csv"; var data = File.ReadLines(filePath).Select(x => x.Split(',')).ToArray(); addAllMissingCrops(data[0]); int currentId; int[] ids = convertNamesToIds(data[0]); using (EntitiesNegev4 context = new EntitiesNegev4()) { CropsConstrainsRepository cropsContains = new CropsConstrainsRepository(context); for (int i = 1; i < data.Length; i++) { currentId = getCropIdByName(data[i][0]); for (int j = 1; j < data[i].Length; j++) { CropConstrains cc = new CropConstrains(); cc.Crop1_Id = currentId; cc.Crop2_Id = ids[j]; cc.NumOfYears = int.Parse(data[i][j]); cropsContains.AddRow(cc); cropsContains.Save(); } } } }