2
我有以下代碼:投放問題
private void EntryBrowserLoad(object sender, EventArgs e)
{
var ase = new AprilShowersEntities();
var q =
from d in ase.Entries
orderby d.EntryEndTime
select d;
var dateQuery = from d in q.AsEnumerable()
select new
{
d.EntryEndTime,
d.EntryId,
d.EntryPlainText,
d.EntryStartTime,
d.EntryText,
EntryHeader = GetEntry(d.EntryEndTime, d.EntryPlainText)
};
lcEntries.DisplayMember = "EntryHeader";
lcEntries.DataSource = dateQuery;
}
private void BtnOkClick(object sender, EventArgs e)
{
var q = (Entry) lcEntries.SelectedItem.Value; // Error here on this line
MessageBox.Show(q.EntryText);
}
我的問題是其獲得上面標線的錯誤,抱怨不能夠把對象放回條目對象。我敢肯定,原因是因爲我在我的LINQ查詢中使用了select new
。我的問題是,我如何讀取返回的SelectedItem.Value對象的EntryText屬性?