I have this query:
SELECT * FROM transaction t JOIN transactionDetail toTrans ON t.id = toTrans.tId and toTrans.FlowDirection= 1 JOIN transactionDetail fromTrans ON t.id = fromTrans.tId and fromTrans.FlowDirection= 0
What I was trying to recreate using anonymous types as described here .
byte toFlow = 1; byte fromFlow = 1; from trans in data.Transactions join toTrans in data.TransactionDetails on new {trans.id, toFlow} equals new {toTrans.tId, toTrans.FlowDirection} join fromTrans in data.TransactionDetails on new { trans.id, fromFlow } equals new { fromTrans.tId, fromTrans.FlowDirection }
Flowdirection is always 1 or 0, so I use the toFlow byte. This, however, gives an error:
The type of one of the expressions in the join clause is invalid.
According to this answer, the name and types must match. That would mean:
byte FlowDirection= 1; from trans in data.Transactions join toTrans in data.TransactionDetails on new {trans.id, FlowDirection} equals new {toTrans.tId, toTrans.FlowDirection} join fromTrans in data.TransactionDetails on new { trans.id, FlowDirection} equals new { fromTrans.tId, fromTrans.FlowDirection }
What works! However, for the second connection, you must have a FlowDirection value of 0 instead of 1. How can I change the FlowDirection value? I cannot change the variable name or subtract 1 inside an anonymous object, otherwise it would be easy.
source share