2

执行以下查询时出现错误

错误: 指定的 LINQ 表达式包含对与不同上下文关联的查询的引用

询问:

var wordlePuzzle = (from wp in wordlepostitionRepository.All
join wtc in wordletextclueRepository.All on wp.WordleTexCluetId equals wtc.WordleTextClueId
join w in wordleRepository.All on wtc.WordleId equals w.WordleId
where wtc.WordleId == id
select new WordlePuzzle
{
   Row = w.WordleRow,
   Column = w.WordleColumn,
   Title = w.WordleTitle,
   DifficultyLevel = DifficultyLevel.Easy,
   Duration = w.WordleDuration,
   ExpiresOn = w.ExpireDate
});

我试过.AsEnumerable();在查询结束后追加,但它仍然给出错误。

对于所有这些表,我只有一个数据库。

4

1 回答 1

2

看看实现工作单元模式,以便您可以跨存储库共享上下文实例。

网上有很多例子,例如http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns -in-an-asp-net-mvc-应用程序

于 2013-04-02T11:35:45.783 回答