Editor in .NET One to Many Join getting error
Editor in .NET One to Many Join getting error
Hei Allan, nice to know your brilliant plugin..
I'm new in .net
But i have some errors with .net plugin which using MJoin (same problem when i use LeftJoin)..
I have table with foreign keys between dbtester and dbtotestergender with iGenders as the key of dbtotestergender..
As look like this:
table: dbtester
| id | name | iGender |
| 1 | Johnny |1 |
| 2 | Elisa | 2 |
table: dbtotestergender
| iGender | sGender |
| 1 | Man |
| 2 | Woman |
Foreign keys at dbtogender:
But i get this error:
{
"draw": null,
"data": [],
"recordsTotal": null,
"recordsFiltered": null,
"error": "Unknown column \u0027dbtotestergender\u0027 in \u0027field list\u0027",
"fieldErrors": [],
"id": null,
"meta": {},
"options": {},
"files": {},
"upload": {
"id": null
}
}
Unknown column 'dbtotestergender' in 'field list' ""
This is the controller:
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult GetEmp()
{
var settings = Properties.Settings.Default;
var formData = HttpContext.Request.Form;
using (var db = new DataTables.Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "dbtester", "id")
.Model<dbtester>()
.Field(new Field("dbtester.id")
.Validator(Validation.NotEmpty())
)
.Field(new Field("dbtester.name")
.SetFormatter(Format.IfEmpty(null))
)
.MJoin(new MJoin("dbtotestergender as gender")
.Link("dbtester.iGender", "gender.iGenders")
.Model<dbtotestergender>()
.Order("gender.iGenders")
.Field(new Field("gender.iGenders")
.Options("gender", "gender.iGenders", "gender.sGender")
)
)
.Process(formData)
.Data();
return Json(response, JsonRequestBehavior.AllowGet);
}
}
Am i wrong in syntax or else? Thanks Allan
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
Answers
Could you try it without the
as gender
alias for the MJoin please? Also, what is in thedbtotestergender
model?Thanks,
Allan
I change my controllers to:
This is dbototestergender table:
And this is dbtotestergender Models (Im using ADO.NET with entity framework for mysql, and this is autogenerated models in my Data Access Layer):
This is my dbtester models:
And still getting same error
I try this:
And still no luck and same errors appeared..
I think
public dbtotestergender()
in the model is the issue. Editor will use reflection to iterate over all of the properties of the model and tears each of them as a field. Could you try simplify the model so it just matches the database for thedbtotestergender
table please? I think that should solve the issue.Regards,
Allan
I comment
public dbtotestergender()
like this:And still no luck, so sorry Allan..
Looking over the data again, it does look like a left join would be more approriate than an
MJoin
here. I'm assuming that each person can have only one gender?In which case:
What does your
dbtester
model contain?Allan
Yes you're right Allan..
dbtester
model (its contained above):Now, im used LeftJoin again but no help:
Thanks for your response until now Allan, hope this prob will clear ASAP..
Thanks - sorry this is taking a while to sort out.
You need to use a nested class as shown here for Editor's .NET libraries when doing a left join. That allows it to tell which field(s) belong to which tables.
Regards,
Allan
Oh Allan, thanks for response and this great answer.. Sorry i didnt read your doc's particularly
I create nested class like this:
Change controller like this:
And edit javascript in view like this:
It works Allan.. Thank you very much
And now i will try cascading dropdown with this
dependent
Fantastic - great to hear it is working for you now!
Allan