Hi,
I've been struggling all day with an MJoin in C# using DataTables Editor .NET (version 2.0.5), but I keep getting the error:
Invalid column name 'ProductStorageLocations'.
I've followed the official guide (https://editor.datatables.net/manual/net/mjoin) and also tried using nested classes as suggested, but without success.
Here’s my code:
public JsonResult Product()
{
var request = System.Web.HttpContext.Current.Request;
using (var db = new Database("sqlserver", "...")
{
var editor = new Editor(db, "Products", "Products.Id")
.Model<ProductEditorDto>("Products")
//...(normal fields here)
.MJoin(new MJoin("ProductStorageLocations")
.Link("Products.Id", "ProductStorageLocationProducts.Product_Id")
.Link("ProductStorageLocations.Id", "ProductStorageLocationProducts.ProductStorageLocation_Id")
.Model<ProductStorageLocationDto>()
.Field(new Field("Id")
.Options("ProductStorageLocations", "Id", "Name")
)
)
.Debug(true);
var response = editor.Process(request).Data();
var jsonResult = Json(response, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
}
And my DTOs:
public class ProductStorageLocationDto
{
public Guid Id { get; set; }
public string Name { get; set; }
}
public class ProductEditorDto
{
// all normal fields here
public List<ProductStorageLocationDto> ProductStorageLocations { get; set; }
// Also tried with:
//public class ProductStorageLocations
//{
// public Guid Id { get; set; }
// public string Name { get; set; }
//}
}
The table and key names are correct, but the error persists.
If I change the property name in ProductEditorDto from ProductStorageLocations to something else (e.g., XY), the error message changes accordingly: Invalid column name 'XY'.
If I remove the property from the DTO I get:
Incorrect syntax near '='.
Additionally, when I try updating to version 2.2.2, I get a different error, unrelated to MJoin:
Method not found: 'System.String[] System.String.Split(Char, System.StringSplitOptions)'.
Any insights into what might be going wrong?
Thanks!