简体   繁体   English

实体框架-LINQ的SQL命令

[英]Entity Framework - SQL command to LINQ

I can't convert this SQL command to LINQ 我无法将此SQL命令转换为LINQ

SELECT tarif.*, prirazeni.Nazev
FROM `tarif`
INNER JOIN prirazeni
ON tarif.intern_id = prirazeni.intern_id
WHERE tarif.id_pojistovna = 'xx' AND cena IS NOT NULL AND prirazeni.nazev = 'yyyy'
GROUP BY id_vstupni_zdroj

My LINQ: 我的LINQ:

var total = (from tarif in context.Tarifs
             join prirazeni in context.Prirazenis on tarif.Intern_id equals prirazeni.Intern_id into joined
             from Join in joined
             where tarif.Id_pojistovna == idPojistovna && Join.Nazev == nazev && tarif.Cena != null && tarif.Id_vstupni_zdroj != idVstupniZdroj 
             group tarif by tarif.Id_vstupni_zdroj into tarifGrouped
             from grouped in tarifGrouped
             select grouped
             ).ToList();

On MySQL Adminer works SQL commands fine but LINQ returns all rows. 在MySQL Adminer上可以正常使用SQL命令,但是LINQ返回所有行。

What's wrong? 怎么了?

I think you have extra into commands try this one. 我认为您对命令有更多的尝试。

var total = (from tarif in context.Tarifs
             join prirazeni in context.Prirazenis on tarif.Intern_id equals prirazeni.Intern_id
             where tarif.Id_pojistovna == idPojistovna && prirazeni.Nazev == nazev && tarif.Cena != null && tarif.Id_vstupni_zdroj != idVstupniZdroj
             group by tarif.Id_vstupni_zdroj
             select new {tarif, prirazeni}).ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM