我使用兩個DataContext對象來返回單獨的AsQueriable()數據集,然後使用linq連接兩個。但是,當我將該組合數據集傳遞給視圖時,數據構造完美地工作,我得到的錯誤'object'不包含'Name'的定義。'object'不包含'Name'的定義
在調試會話期間,我可以清楚地看到父級模型和foreach循環中的每個「項目」都具有可見/可訪問的所有數據和鍵。我很困惑。
許多其他問題匹配此問題的stackoverflow.com上的a不能解決我的問題,因此將欣賞一組全新的眼睛,並希望解決這個問題。
非常感謝! - 代碼時間:
的數據結構
public ActionResult SplashImages()
{
var g = (from i in GetGallerySplash() join o in GetFestivals() on i.Festival equals o.ID orderby i.Rating descending select new {i.Photo, i.OwnedBy, i.Rating, o.Name });
Response.ContentType = "text/xml";
return View(g);
}
private IEnumerable<Gallery> GetGallerySplash()
{
GallerysDataContext gdc = new GallerysDataContext();
return (from i in gdc.Galleries orderby i.Rating descending select i).Take(15).AsQueryable();
}
private IEnumerable<Festival> GetFestivals()
{
FestivalsDataContext fdc = new FestivalsDataContext();
return (from i in fdc.Festivals select i).AsQueryable();
}
VSExpress的錯誤畫面:
在溶液中的任何指導,將不勝感激。謝謝!
Ç
[訪問C#匿名類型對象](http://stackoverflow.com/questions/713521/accessing-c-sharp-anonymous-type-objects) – nawfal 2014-06-28 12:49:07