Left Join causes value to be null
Left Join causes value to be null
airmaster
Posts: 72Questions: 15Answers: 2
I just posted a separate issue, and I think I solved my problem, but now I have a different problem and am not sure.
Tables defined as before:
public class tblWinLoss
{
public int ID {get;set;}
public string Title {get;set;}
public int CustomerID {get;set;}
public int SupplierID {get;set;}
}
public class tblCompany
{
public int ID {get;set;}
public string CompanyName {get;set;}
}
and
public class JoinWinLoss
{
public int ID {get;set}
public string Title { get; set; }
}
public class JoinCompany
{
public int ID { get; set; }
public string CompanyName { get; set; }
}
If I run the query
var Response = new Editor(db, "tblWinLoss")
.Model<JoinWinLoss>("tblWinLoss")
.Field(new Field("tblWinLoss.ID", "WinLossID"))
.Process(request)
.Data();
I get
{
"DT_RowId": "row_5",
"WinLossID": "5",
"tblWinLoss": {
"ID": 5,
"Title": "My Title"
}
},
If I add in a left join, the value for the ID disappears
var Response = new Editor(db, "tblWinLoss")
.Model<JoinWinLoss>("tblWinLoss")
.Field(new Field("tblWinLoss.ID", "WinLossID"))
.LeftJoin("tblCompany", "tblCompany.ID", "=", "tblWinLoss.CustomerID")
.Process(request)
.Data();
{
"DT_RowId": "row_5",
"WinLossID": null,
"tblWinLoss": {
"ID": null,
"Title": "My Title"
}
},
Considering that tblWinLoss.ID cannot be null, and this is a left join, how can this be?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I don't know! Could you add
.Debug(true)
immediately before the.Process(...)
call please? That will show the SQL that Editor generates in the returns JSON. Could you show me that JSON? Hopefully that will let me understand what is going wrong.Thanks,
Allan
Browsing last night, I found the fix. All I had to do was include "ID" in the Editor constructor. I have no idea why, and I am not home, so I don't have the link to that thread.
I wonder if this a bug, or it should be in the manual.
I didn't know that there was a Debug feature. That's great to hear and will be useful. Thanks for your time.
Would you still like me to post the debug without the ID?
Ah! The default is "id" (lowercase), so yes, if you wanted anything else, then the correct thing to do would be to give it as the third parameter.
Thanks for noting that.
Allan