[英]Need Help for Join tables in Linq on ASP.NET Core
basically i am working on ASP.NET Core and I have an FromSqlRaw statement which filters and keeps some ids in a value of a talbe (ActiveCalls).基本上我正在研究 ASP.NET 核心,我有一个 FromSqlRaw 语句,它过滤并将一些 id 保存在一个 talbe 的值(ActiveCalls)中。 Then with Linq I filter another table of database (AppUsers).
然后用 Linq 我过滤另一个数据库表(AppUsers)。 My goal is to keep all columns of Appusers with Ids i take from ActiveCalls.
我的目标是使用我从 ActiveCalls 获取的 ID 保留所有 Appuser 列。
Code for SqlRaw with Ids result: (13) Correct!带有 ID 结果的 SqlRaw 代码:(13) 正确!
var results = _context.ActiveCalls.FromSqlRaw("SELECT web_userid from ActiveCalls where TimeReceived>'2021-01-01' and GeoX > 23.8097593342164 and GeoX < 23.8838031312548 and GeoY > 38.1026672246045 and GeoY < 38.1607577524088 group by web_userid");
Code for Linq with data:Result (2281) Correct! Linq 的代码与数据:结果(2281)正确!
appusers = appusers.Where(s => s.LastCall >= start && s.LastCall <= end);
Code for Join tables to keep only Records of AppUsers based on Ids i found on ActiveCalls.加入表的代码,仅保留基于我在 ActiveCalls 上找到的 Id 的 AppUser 记录。 Result(10) Wrong!
结果(10) 错误!
appusers = from res in results
join ap in appusers
on res.web_userid equals ap.Id
select ap;
I have to take the result with Linq and those 3 steps and not merge all in on Sql query我必须使用 Linq 和这 3 个步骤来获取结果,而不是在 Sql 查询中全部合并
I don't get an idea of using FromSqlRaw
in this case.在这种情况下,我不知道使用
FromSqlRaw
。
var results =
from ac in _context.ActiveCalls
where ac.TimeReceived > DateTime.Parse("2021-01-01")
&& ac.GeoX > 23.8097593342164
&& ac.GeoX < 23.8838031312548
&& ac.GeoY > 38.1026672246045
&& ac.GeoY < 38.1607577524088
select ac.web_userid;
results = results.Distinct();
var appusers = _context.AppUsers.AsQueryable();
appusers = appusers.Where(s => s.LastCall >= start && s.LastCall <= end);
appusers =
from res in results
join ap in appusers on res.web_userid equals ap.Id
select ap;
If you still does not have correct result, it means that AppUser.Id
is not web_userid
如果仍然没有正确的结果,则表示
AppUser.Id
不是web_userid
Try Somthing like this试试这样的东西
var results = _context.ActiveCalls.FromSqlRaw("SELECT web_userid from ActiveCalls where TimeReceived>'2021-01-01' and GeoX >
23.8097593342164 and GeoX < 23.8838031312548 and GeoY > 38.1026672246045 and GeoY < 38.1607577524088 group by web_userid");
appusers = appusers.Where(s => s.LastCall >= start && s.LastCall <= end && results.web_userid.contains(s.Id));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.