ServiceStack ORM Lite Left Join query filter

46 Views Asked by At

I am not able to filter out the records correctly.

q = q.LeftJoin<PurchaseInvoice, PurchaseInvoiceProjectLink>((pi, pipl) => pi.Id == pipl.PurchaseInvoiceId);
q = q.Where<PurchaseInvoiceProjectLink>(s => Sql.In(s.ProjectId, UserSession.ProjectIds)) || s == null );

The s == null part does not work and I see it is materialised in the sql query into OR ('{}' is null))

I am not sure if it is a bug in Servicestack ORM Lite or the code should be written in other way.

====

OK. I haved resolved this as below (but still looking something to not use pragma.

#pragma warning disable CS0472 // The result of the expression is always the same since a value of this type is never equal to 'null'
            q = q.Where<PurchaseInvoiceProjectLink>(s => ... ||  s.PurchaseInvoiceId == null);
#pragma warning restore CS0472 // The result of the expression is always the same since a value of this type is never equal to 'null'
1

There are 1 best solutions below

5
labilbe On

Try

q = q.LeftJoin<PurchaseInvoice, PurchaseInvoiceProjectLink>((pi, pipl) => pi.Id == pipl.PurchaseInvoiceId).Where<PurchaseInvoiceProjectLink>(s => s.Id == null || UserSession.ProjectIds.Contains(s.ProjectId));