gpt4 book ai didi

c# - 如何使用 LINQ to SQL 和 C# 进行正确的连接?

转载 作者:太空狗 更新时间:2023-10-29 22:14:29 25 4
gpt4 key购买 nike

我在使用 LINQ 和 C# 创建以下 SQL 语句时遇到问题

    select c.IDAddenda, c.Descripcion
from CatAddendas c
right join EmpresaAddenda e on e.IDAddenda = c.IDAddenda
where e.rfc = 'SUL010720JN8'
order by c.IDAddenda asc

我明白了:

public IEnumerable<CatAddenda> TraeAddendas(string rfc)
{
DataClasses1DataContext dc = new DataClasses1DataContext(...);

return (from adds in dc.EmpresaAddendas
cats.IDAddenda into joined
where adds.RFC == rfc
select adds.CatAddenda);
}

这不是正确的连接,所以有什么想法吗?

最佳答案

 var RightJoin = from adds in dc.EmpresaAddendas
join cats in CatAddendas
on adds.IDAddenda equals cats.IDAddenda into joined
from cats in joined.DefaultIfEmpty()
select new
{
Id = cats.IDAddenda,
Description = cats.Descripcion
};

关于c# - 如何使用 LINQ to SQL 和 C# 进行正确的连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9914623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com