Wednesday, 15 August 2012

sql - ServiceStack OrmLite LeftJoin Issue -



sql - ServiceStack OrmLite LeftJoin Issue -

i'm using servicestack ormlite joinsqlbuilder left bring together , have found issue. suppose have 2 tables, tablea , tableb , wanted bring together on more single value.

in sql this:

select tablea.name, tableb.value tablea left bring together tableb on tableb.aid = tablea.id , tableb.postcode = '12345'

now joinsqlbuilder allows joins on single column , generates sql so

select tablea.name, tableb.value tablea left bring together tableb on tableb.aid = tablea.id tableb.postcode = '12345'

which not same thing @ all!

is there way around in servicestack ormlite? here illustration of left joins clauses: left bring together clause

you should able utilize new back upwards join's in ormlite's typed sqlexpressions. it's best utilize latest v4.0.23 release on myget includes improved back upwards selecting multiple columns across joined tables.

with new bring together api's can need like:

public class tablea { public int id { get; set; } public string name { get; set; } } public class tableb { public int aid { get; set; } public string postcode { get; set; } public string value { get; set; } } public class tableabfields { public string tableaname { get; set; } public string tablebvalue { get; set; } } var results = db.select<tableabfields,tablea>(q => q.join<tablea,tableb>((a,b) => b.aid == a.id && b.postcode == "12345"));

alternative api using explicit sql expression:

var q = db.from<tablea>(); // or var q = ormliteconfig.dialectprovider.sqlexpression<tablea>(); q.join<tablea,tableb>((a,b) => b.aid == a.id && b.postcode == "12345"); var results = db.select(q);

sql servicestack left-join ormlite-servicestack

No comments:

Post a Comment