如何使用LINQ to SQL和C#进行正确的连接
发布时间:2021-02-23 16:40:10 所属栏目:编程 来源:网络整理
导读:嘿伙计们,我在使用LINQ创建以下SQL语句时遇到问题C# 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 IEnumerableCat
|
嘿伙计们,我在使用LINQ&创建以下SQL语句时遇到问题C# 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
}; (编辑:厦门网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |

