【发布时间】:2017-08-02 03:56:46
【问题描述】:
尝试将实体映射到 DTO 时,出现以下错误。
LINQ to Entities 无法识别方法 'Dto.Team ToTeamDto(Team, System.String)' 方法,而该方法不能 翻译成商店表达式。”
这里是查询
bool includeTeam = true;
var source = from c in db.Standings
where c.LeagueID == leagueId
select new Standing
{
id = c.StandingsId,
team = includeTeam ? c.Team.ToTeamDto("en-US") : null
};
以及扩展方法
internal static Dto.Team ToTeamDto(this Team team, string locale)
{
return new Dto.Team
{
id = team.TeamID,
name = team.name
};
}
这个有什么问题吗? 我该如何解决?
【问题讨论】:
标签: c# entity-framework linq extension-methods dto