【发布时间】:2010-12-31 18:26:57
【问题描述】:
在 WPF 应用程序中,我有一个 Observable Collection,它通过数据绑定与 ListView 连接。我想从 LINQ 到 SQL 查询填充这个 Observable Collection,但没有成功。事实上,我的代码甚至无法编译(我指出了 cmets 的问题行)。
底层 Observable Collection Class 的结构类似于我尝试从中获取查询的 SQL 表的结构。
请问,我的方法有什么问题?
这是我的部分代码:
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
});
}
}
【问题讨论】:
标签: c# sql wpf linq linq-to-sql