2010-01-02 3 views
3

WPF 응용 프로그램에서 ListView와 데이터 바인딩을 통해 연결되는 Observable Collection이 있습니다. 이 Observable Collection을 LINQ에서 SQL 쿼리로 채우고 싶습니다만 성공하지는 못했습니다. 실제로 제 코드는 컴파일되지 않습니다 (나는 주석으로 문제 라인을 지적했다).SQL 쿼리 결과에 LINQ를 Observable Collection에 추가하는 방법은 무엇입니까?

Observable Collection 클래스의 구조는 쿼리를 가져 오는 SQL 테이블의 구조와 비슷합니다.

내 접근 방식에 문제가 있습니까? 당신은 foreach(var p in context.Shows) {...}를 사용할 수, BTW

foreach (var p in sh) { 
    _ShowCollection.Add(new ShowsQu { 
     Date = p.Date, 
     Time = p.Time, 
     Description = p.Description 
    }); 
} 

: sh/p (sh 쿼리입니다 p는 현재 반복기 항목)

ObservableCollection<ShowsQu> _ShowQuCollection = 
      new ObservableCollection<ShowsQu>(); 

    public ObservableCollection<ShowsQu> ShowQuCollection 
    { get { return _ShowQuCollection; } } 

    public class ShowsQu 
    { 
     public string ShowCode { get; set; } 
     public DateTime Date { get; set; } 
     public TimeSpan Time { get; set; } 
     public string Description { get; set; } 
    } 

    private void VisualizeAllShows() 
    { 

     MyfirstdbDataContext context = new MyfirstdbDataContext(); 
     _ShowQuCollection.Clear(); 

     var sh = from p in context.Shows select p; 

     foreach (var p in sh) 
      _ShowCollection.Add(new ShowsQu 
      { 
       Date = sh.Date, //here is compile-time error 
       Time = sh.Time, //here is compile-time error 
       Description = sh.Description //here is compile-time error 
      }); 
     }   
    } 

답변

2

SUBST : 여기

내 코드의 일부입니다 이리.

+0

예, 그렇습니다. 많은 감사합니다! 그것은 작동합니다. 내가 얼마나 어리석은 mitake를 만들었고, 몇 시간 동안 그것을 지방화 할 수 없었다! – rem

+0

그리고 마지막 라인의 팁을 보내 주셔서 감사합니다. – rem

+0

신선한 눈은 종종 유용합니다; –

관련 문제