Hi
I'm trying to implement a link table called GlobalSubsPacksRelations below. It stores IDs from GlobalSubsPacks.ID via GlobalSubsPacksRelations.SubPackID. It's a one-to-many relationship between these 2 tables as GlobalSubsPacksRelations effectively stores IDs from various other tables via GlobalSubsPacksRelations.ParamID, one being GlobalPacksVoiceParam.ID. GlobalSubsPacks stores sales bundles the parts of which are stored in GlobalSubsPacksRelations via ParamID. There is one line in GlobalSubsPacksRelations per bundle part.
I am trying to display in a DT all the bundles and also set fields such as GlobalPacksVoiceParam.CustomerType so I can show the individual parts of bundles in an Editor form. I keep getting error 'Invalid column name 'SubPackID'' with code below. Any help would be greatly appreciated.
Server:
HttpRequest formData = HttpContext.Current.Request; using (Database db = new Database(SetGetDbType2, SetGetDbConnection)) { editor = new Editor(db, "GlobalSubsPacks", "GlobalSubsPacks.id") .Model<SubsPacksDBModel.GlobalSubsPacks>("GlobalSubsPacks") .Model<SubsPacksDBModel.GlobalSubsPacksRelations>("GlobalSubsPacksRelations"); editor.MJoin(new MJoin("GlobalPacksVoiceParam") .Model<SubsPacksDBModel.GlobalPacksVoiceParam>() .Name("GlobalPacksVoiceParam.CustomerType") .Link("GlobalPacksVoiceParam.id", "GlobalSubsPacksRelations.ParamID") .Link("GlobalSubsPacks.id", "GlobalSubsPacksRelations.SubPackID") .Field(new Field("id") .Options(new Options() .Table("GlobalPacksVoiceParam") .Value("id") .Label("CustomerType") ) .Set(false) ) .Set(false) ); editor.TryCatch(false); editor.Debug(true); editor.Process(formData);JS:
var editor = new $.fn.dataTable.Editor({ destroy: true, ajax: { url: '/Packages/CRUDPackages/', type: 'POST', async: true, cache: false }, table: '#tblDataTable', fields: [ { label: '', name: 'GlobalSubsPacks.id' }, { label: 'CustomerType', name: 'GlobalPacksVoiceParam.CustomerType', type: 'select', options: [ ... @Html.Raw(strTp) ], def: 'default' } ] }); var dataTable = $('#tblDataTable').DataTable( { dom: 'Bfrtip', ajax: { url: '/Packages/CRUDPackages/', type: 'GET', dataType: 'json', contentType: 'application/json; charset=utf-8', async: true, cache: false }, columns: [ { data: 'GlobalSubsPacks.id' , className: 'text-left' }, { data: 'GlobalPacksVoiceParam.CustomerType' , className: 'text-left' } ], select: true, buttons: [ { extend: 'create', editor: editor }, { extend: 'edit', editor: editor }, { extend: 'remove', editor: editor } ] });Model:
public class SubsPacksViewModel
{
public class GlobalSubsPacks
{
public long ID { get; set; }
public string Name { get; set; }
}public class GlobalSubsPacksRelations { public long ID { get; set; } public long SubPackID { get; set; } //stores GlobalSubsPacks.ID public long ParamID { get; set; } //stores GlobalPacksVoiceParam.ID public int Exported { get; set; } } public class GlobalPacksVoiceParam { public long ID { get; set; } public long SubPackID { get; set; } //stores GlobalSubsPacks.ID public string CustomerType { get; set; } }}