devforce - Join with distinct - Translating SQL to Linq Query -



devforce - Join with distinct - Translating SQL to Linq Query -

i trying translate sql query working linq statement, unfortunately not easy expected.

the original sql query looks following:

select distinct tt1.artikelid ( select artikelid [dbo].[artsearcheinfachview] feld = 'listungsstatus' , wert = '0' ) tt1 inner bring together ( select artikelid [dbo].[artsearcheinfachview] feld = 'aktiveraktikel' , wert = '1' ) tt2 on tt1.artikelid = tt2.artikelid inner bring together ( select artikelid [dbo].[artsearcheinfachview] feld = 'artikelbezeichnung' , wert '%berentzen%' ) tt3 on tt1.artikelid = tt3.artikelid

there more joins later on, build predicate builder later on, page included 2.

i tried convert it. using devforce entity manager, unfortunately not working:

public async task<int> ladeartikelcounteinfachnew(string sucheingabe) { var query = _artikelcontainer.artsearcheinfach.where(p => p.feld == "listungsart" && p.wert == "0"); query = query.join(_artikelcontainer.artsearcheinfach.where(x => x.feld == "aktiveraktikel" && x.wert == "1"), x => x.artikelid, y => y.artikelid, (x,y) => y).distinct(); query = query.join(_artikelcontainer.artsearcheinfach.where(p => p.feld == "artikelbezeichnung" && p.wert.contains(sucheingabe)), x => x.artikelid, y => y.artikelid, (x, y) => y).distinct(); homecoming await query.asscalarasync().count(); }

someone please help me?

i can't understand why you're using multiple inner joins on same table instead of and/or clauses, i'll assume there's reason this. closest analogous linq query you're doing this, uses anonymous projections:

var query = _artikelcontainer.artsearcheinfach .where(p => p.feld == "listungsart" && p.wert == "0") .select(p => new { p.artikelid } ); query = query.join(_artikelcontainer.artsearcheinfach .where(x => x.feld == "aktiveraktikel" && x.wert == "1") .select(x => new { x.artikelid } ), x => x.artikelid, y => y.artikelid, (x,y) => y); query = query.join(_artikelcontainer.artsearcheinfach .where(p => p.feld == "artikelbezeichnung" && p.wert.contains(sucheingabe)) .select(p => new { p.artikelid } ), x => x.artikelid, y => y.artikelid, (x, y) => y); var results = await query.distinct().executeasync();

linq-to-entities devforce

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -