gpt4 book ai didi

c# - 使用连接循环遍历动态 linq 对象

转载 作者:太空宇宙 更新时间:2023-11-03 20:12:10 25 4
gpt4 key购买 nike

我有以下功能

 public List<Object> GetEventsForAdmin()
{
using (var dbEntities = new CapeledEntities())
{
return (from e in dbEntities.Events
join lnk in dbEntities.linkEventCategories on e.EventId equals lnk.EventId
join cat in dbEntities.Categories on lnk.CategoryId equals cat.CategoryId
orderby e.StartDateTime descending
select new {
e.EventId,
EventTitle = e.Title,
e.StartDateTime,
e.Description,
CatTitle = cat.Title
}
).ToList<Object>();
}
}

我正在使用

  var eventHelper = new BusinessLogic.DatabaseAccess.Helpers.BLEvents();
foreach (var myEvent in eventHelper.GetEventsForAdmin())
{
txtTitle.text = myEvent.CatTitle;
txtDescription.text = myEvent.description;
}

但是找不到 myEvent.CatTitle 和 myEvent.description 啊

  }

最佳答案

改变

foreach (var myEvent in eventHelper.GetEventsForAdmin())

foreach (dynamic myEvent in eventHelper.GetEventsForAdmin())

这应该允许您访问已转换为对象的匿名类型的成员。

关于c# - 使用连接循环遍历动态 linq 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19336426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com