2016-09-19 5 views
0

나는 각 Student 클래스를 가지고 있는데, 각 ID에는 시험 목록이 있으며 시험 열을 Exams_Line_list 속성에 매핑해야합니다. 엑셀 시트를 읽기 Exams_Line_list목록에 추가 매핑 열

public class Student 
    { 
     string id; 
     public List<String> exams_Line_list = new List<String>(); 
     public String exams_Line1; 

     public string Exams_Line1 
     { 
      get { return exams_Line1; } 
      set { exams_Line1 = value; } 
     } 

     public string ID 
     { 
      get { return id; } 
      set { id = value; } 
     } 

     public List<String> Exams_Line_list 
     { 
      get { return exams_Line_list; } 
      set { exams_Line_list = value; } 
     } 
} 

빈 다음 코드 반환 :

IQueryable<Student> Students_var; 
var excel = new ExcelQueryFactory(fileName_global1); 

excel.AddMapping<Student>(x => x.ID, "STU_NO"); 
excel.AddMapping<Student>(x => x.Exams_Line1, "Exam"); 
Students_var = from c in excel.Worksheet<Student>("Stu_Schedule") 
       select c; 

List<Student> StudentList_c = Students_var.ToList(); 

var grouped = StudentList_c.GroupBy(x => x.ID).Select(x => new Student 
       { 
       ID = x.Key, 
       Exams_Line_list = x.SelectMany(z => z.Exams_Line_list).ToList() 
       }).ToList(); 

foreach (var r in grouped) 
{ 
    Console.WriteLine(r.ID); 
     foreach (String s1 in r.Exams_Line_list) 
        Console.WriteLine(s1); 
} 

스키마 :

enter image description here 나는 시험 열을 매핑 할 문자열 속성을 추가해야

(Exams_Line1) 중단 점 StudentList_c enter image description here

지금 각 시험 값과 중복 ID를 포함하는 모든 행을 읽을 수 있지만 정의 된 목록에 그룹을에 (Exams_Line1)

+0

줄'var grouped = StudentList_c.GroupBy ... '앞에 중단 점을 추가하여'StudentList_c' 안에 무엇이 있는지 확인할 수 있습니까? 특히 시험 문자열의 정확한 값이 포함되어 있는지 확인하십시오. –

+0

예, 질문이 업데이트되었습니다. –

+0

괜찮습니다. 편집 된 버전 –

답변

0

가 될 수있는 방법 당신은 그냥 사용할 수 있습니다 : 여기

var grouped = StudentList_c.GroupBy(x => x.ID).Select(x => new Student 
{ 
    ID = x.Key, 
    Exams_Line_list = x.Select(z => z.Exams_Line1).ToList() 
}).ToList(); 

을 나는 Student_List이 엑셀 시트의 행에 해당하는 모든 행을 가지고 있으며 Exams_Line1 속성이 Exam 열로 매핑되고 있다고 가정합니다.

+0

오류 ' System.Collections.Generic.List' –

+0

Exams_Line1 문자열하지만 Exams_Line_list 목록

+0

감사합니다입니다 암시 적으로 유형 'System.Collections.Generic.List 을'변환 할 수 없습니다 , 내 시간을 절약 할 수 있습니다 :) –