我无法返回IEnumerable和IList,我无法做到这一点! 我使用EF 4波苏斯返回IEnumerable的问题<T>/IList <T>
这里是整个方法:
//public IList<Genre> GetGenresByGame(int gameId)
public IEnumerable<Genre> GetGenresByGame(int gameId)
{
using(var ctx = new XContext())
{
var results =
from t0 in ctx.GameGenres
join t1 in ctx.GenreCultureDetails on t0.GenreId equals t1.GenreId
where t0.GameId == gameId && t1.CultureId == _cultureId
select new Genre
{
GenreId = t0.GenreId,
GenreName = t1.GenreName
};
return results.ToList();
}
}
我已经试过,我在网上找到不同的方式..但不能使它的工作!
问题2: 我在Julie看到一个截屏视频,说使用EF4时应该总是返回一个ICollection。
对此有何想法?
BR
编辑: 当我加载页面在调试模式下,我得到这些错误:The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. OR The entity or complex type 'XModel.Genre' cannot be constructed in a LINQ to Entities query
。
什么在这里不起作用? – Snowbear 2011-03-17 19:59:54
只是一个随机问题,但你的数据库中存在流派吗?如果是这样,你为什么不选择呢? – Nix 2011-03-17 20:18:25
是的,Genre确实存在于数据库中。选择,你是什么意思? – n3tx 2011-03-17 20:20:39