Selft Join - C#
Selft Join - C#
Hi,
I am trying to use the self join code example. I have the User table that is joined to the Requisition table using the User_ID field which works fine.
I am trying to join another User table to the Requisition table using the CurrentUser_ID field as highlighted below but doesn't work.
What is wrong with the way I am applying the self join?
var response = new Editor(db, "Requisition", "ID")
.Model<Requisition>("Requisition")
.Model<User>("User")
.LeftJoin("dbo.User", "User.ID", "=", "Requisition.User_ID")
.Field(new Field("Requisition.User_ID")
.Options("dbo.User", "ID", "Username")
.Set(Field.SetType.Create).SetValue(User_ID)
.Validator(Validation.DbValues(new ValidationOpts { Empty = false }))
)
.Model<User>("CurrentUser")
.LeftJoin("dbo.User as CurrentUser", "CurrentUser.ID", "=", "Requisition.CurrentUser_ID")
.Field(new Field("Requisition.CurrentUser_ID")
.Options("CurrentUser", "ID", "Username")
)
.Process(formData)
.Data();
Thanks in advance for your help.
---Stephen
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
Hi Stephen,
Are you getting an error when you run that, or something else? If an error, what is it?
Also, you could you try adding
.Debug(true)
immediately before the.Process(...)
call and show me the JSON response from the server please?Thanks,
Allan
Hi,
There is no error from the server side. However, the client returns the following alert message: DataTables warning: table id=Table_Requisition - Incorrect syntax near the keyword 'User'.
The JSON response is as follows:
Thanks,
--Stephen
Hi Stephen,
Could you replace:
with:
It looks like the escaping might be wrong (actually, non-existent) for cases when an alias is given.
Thanks,
Allan
Hi Allan,
Thanks for the response once again.
I did the replacement but I get DataTables warning: table id=Table_Requisition - Duplicate field detected - a field with the name
Requisition.CurrentUser_ID
already exists from the client side.The JSON response is as follows:
Thanks,
---Stephen
Hi Stephen,
That means you have two fields with the name
Requisition.CurrentUser_ID
on the client-side I think. Can you show me the Javascript for your Editor and also the data being submitted to the server-side please?Thanks,
Allan
Hi Allan,
Once again, thanks for the response.
The details as requested are below:
Editor:
Datatable:
There is no data sent to the server.
Thanks,
---Stephen
Hi Stephen,
I have to apologise - I got totally confused yesterday and thought it was an issue when submitting the data. In fact it is when it is reading the data the error comes up I understand now... Sorry about that!
This is part of the query being executed:
I can see that there is:
Which is what is causing this error. As to why it is happening... Could you show me your full C# code for this instance please?
Thanks,
Allan
Hi Allan,
Apologies for the delay in responding. I had some emergencies to take care of.
Kindly find below as requested:
Thanks,
---Stephen
Hi Stephen,
Could you show me the models you are using here as well please. I suspect we will need to try to recreate this, to understand what is going wrong.
Allan
Hi Allan,
Thanks for the response.
Kindly find below the models:
Requisition:
User:
Item:
Item Group:
Subsidiary:
Location:
Department:
Unit:
Vendor:
Thanks,
---Stephen