我正在使用LINQ从EF上下文以及Asp .Net Identity 2.0中检索数据 - 它们都位于同一个MS SQL Server数据库中。
问题是,LINQ将它们视为不同的数据上下文,并且无法处理查询。
"The specified LINQ expression contains references to queries that are associated with different contexts."
我想要实现的是从EF表中返回排过序的前10个项目(在代码片段中我跳过了这一步),先按照ASP .NET身份表中的用户名排序。
我在StackOverflow上看到了几个类似的问题,但是在我的情况下无法应用任何解决方案。
当然,首选的解决方案是不下载整个表格数据,在服务器上进行排序。
有问题的查询如下:
var dbDataSorted = from entry in dbData
join user in this.UserManager.Users
on entry.UserId equals new Guid(user.Id)
orderby user.UserName ascending
select entry;
return dbDataSorted;