2014-11-05 1 views
-1

난 내가 같은 사용 Linq.I가 학습 엔티티 Framework.Sorry을 시작 어떻게 내가 할이모든 관련 엔티티를로드하는 방법은 무엇입니까?

public static ObservableCollection<ResItem> GetResult(DataSet ds) 
    { 

     ObservableCollection<ResItem> data=new ObservableCollection<ResItem>(); 
     foreach (DataRow dr in ds.Tables["Discipline"].Rows) 
     { 
      ResItem disc=new ResItem("","","","","","",dr["Discipline"].ToString(),0,0); 
      foreach (DataRow child1 in dr.GetChildRows("Disc-Test")) 
      { 
       ResItem i1=new ResItem("","","","","",child1["TestName"].ToString(),"",0,0); 
       disc.Items.Add(i1); 
       foreach (DataRow child2 in child1.GetChildRows("Test-Statement")) 
       { 
        foreach (DataRow child3 in child2.GetChildRows("Group-Statement")) 
        { 
         ResItem i2 = new ResItem("", "", "", "", child3["GName"].ToString(), "", "",Convert.ToInt32(child2["StatementId"]),0); 
         i1.Items.Add(i2); 
         foreach (DataRow child4 in child2.GetChildRows("Statement-Result")) 
         { 
          foreach (DataRow child5 in child4.GetChildRows("Student-Result")) 
          { 
           ResItem i3 = new ResItem(child4["DatePass"].ToString(),child4["Point"].ToString(), child5["LastName"].ToString(), child5["FirstName"].ToString(), "", "", "",0,Convert.ToInt32(child4["ResultId"])); 
           i2.Items.Add(i3); 
          } 
         } 
        } 
       } 
      } 
      data.Add(disc); 
     } 
     return data; 
    } 

이 말하지 마 데이터 세트로 작업 할 때 결과 테이블 에서 모든 관련 개체를로드하고자하는 내 나쁜 영어

+0

코드에서 정확히 무엇이 일어나고 있습니까? 그것은 많은 'foreach'진술로는 조금 읽을 수 없습니다. 'ResItem' 클래스 및/또는 데이터 모델을 보여줄 수 있습니까? – Marthijn

답변

-1
class ResulViewModel:ViewModelBase 
{ 
    readonly Discipline _discipline=new Discipline(); 
    readonly Test _test=new Test(); 
    readonly Group _group=new Group(); 
    readonly Student _student=new Student(); 
    readonly Result _result=new Result(); 
    private string _timePass; 


    public string Discipline 
    { 
     get { return _discipline.Discipline1; } 
     set { _discipline.Discipline1 = value; RaisePropertyChanged("Discipline"); } 
    } 

    public string Test 
    { 
     get { return _test.TestName; } 
     set { _test.TestName = value; RaisePropertyChanged("Test");} 
    } 

    public string Group 
    { 
     get { return _group.GName; } 
     set { _group.GName = value; RaisePropertyChanged("Group");} 
    } 

    public string Surname 
    { 
     get { return _student.LastName; } 
     set { _student.LastName = value; RaisePropertyChanged("Surname");} 
    } 

    public string Name 
    { 
     get { return _student.FirstName; } 
     set { _student.FirstName = value; RaisePropertyChanged("Name");} 
    } 

    public string Point 
    { 
     get { return _result.Point; } 
     set { _result.Point = value; RaisePropertyChanged("Point");} 
    } 

    public string TimePass 
    { 
     get { return _timePass; } 
     set { _timePass = value; } 
    } 

    public ObservableCollection<ResulViewModel> Items { get; set; } 


    public ResulViewModel(string timePass, string point, string name, string surename, string @group, string test, string discipline) 
    { 
     TimePass = timePass; 
     Point = point; 
     Name = name; 
     Surname = surename; 
     Group = @group; 
     Test = test; 
     Discipline = discipline; 


     Items = new ObservableCollection<ResulViewModel>(); 
    } 
} 
관련 문제