Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Linq选择具有匹配子项的父/父记录_C#_Linq_Linq To Entities - Fatal编程技术网

C# Linq选择具有匹配子项的父/父记录

C# Linq选择具有匹配子项的父/父记录,c#,linq,linq-to-entities,C#,Linq,Linq To Entities,使用ef core并尝试根据子项中的条件选择父项 如果我在sql中这样做,我会 declare @UserName nvarchar(200) set @UserName = 'al65272' declare @ClientId int set @ClientId = 32 select u.* from Users u inner join ClientUsers cu on u.Id = cu.UserId where NormalizedUserName = upper(@

使用ef core并尝试根据子项中的条件选择父项

如果我在sql中这样做,我会

    declare @UserName nvarchar(200)
set @UserName = 'al65272'

declare @ClientId int
set @ClientId = 32

select u.*
from Users u 
inner join ClientUsers cu on u.Id = cu.UserId
where NormalizedUserName = upper(@UserName) and cu.ClientId=@ClientId
我想我可以这样做:

var userByUserName = _applicationDbContext.Users.FirstOrDefault(x =>
                x.NormalizedUserName == userName.ToUpper() &&
                x.ClientUsers.Contains(new ClientUser {ClientId = client.Id, User = x}));
但显然是错误的,因为没有返回任何内容


有人能给我指出正确的方向吗?

我想这对你来说很有用:

var userByUserName = _applicationDbContext.Users.FirstOrDefault(x =>
                x.NormalizedUserName == userName.ToUpper() &&
                x.ClientUsers.Any(c => c.ClientId == client.Id));

在提供的SQL中,您寻址两个表AspNetUsers和ClientUser,但在LINQ中,您寻址用户。你能用正确的数据编辑你的帖子吗?对不起,谢谢。现在更正