Multiple one-to-many's

Multiple one-to-many's

dynasoftdynasoft Posts: 439Questions: 68Answers: 3

Hi

I'm using Mjoins to show a one-to-many relationship. I have 2 fields in a dt that show different string values (PriceList) based on the value of an other field (PriceListType). The db table (CustomerVoiceCLIPriceLists) is the same for both fields. Values under these 2 fields are shown to the user in 2 separate columns in JS code.

  • Server
    ...
    editor.MJoin(new MJoin("CustomerVoiceCLIPriceLists")
    .Link("CustomerVoiceCLI.CustID", "CustomerVoiceCLIPriceLists.CustomerIndex")
    .Link("CustomerVoiceCLI.id", "CustomerVoiceCLIPriceLists.CustomerVoiceCLIIndex")
    .Model<CustomerSNsDBModel.CustomerVoiceCLIPriceLists>()
    .Order("CustomerVoiceCLIPriceLists.CustomerVoiceCLIIndex ASC")
    .Field(new Field("id")
    .Options(new Options()
    .Table("CustomerVoiceCLIPriceLists")
    .Value("id")
    .Label("PriceList")
    )
    )
    .Where("CustomerVoiceCLIPriceLists.PriceListType", 0)
    );
    editor.MJoin(new MJoin("CustomerVoiceCLIPriceLists")
    .Link("CustomerVoiceCLI.CustID", "CustomerVoiceCLIPriceLists.CustomerIndex")
    .Link("CustomerVoiceCLI.id", "CustomerVoiceCLIPriceLists.CustomerVoiceCLIIndex")
    .Model<CustomerSNsDBModel.CustomerVoiceCLIPriceLists>()
    .Order("CustomerVoiceCLIPriceLists.CustomerVoiceCLIIndex ASC")
    .Field(new Field("id")
    .Options(new Options()
    .Table("CustomerVoiceCLIPriceLists")
    .Value("id")
    .Label("PriceList")
    )
    )
    .Where("CustomerVoiceCLIPriceLists.PriceListType", 1)
    );
    ...

  • Model:

    public class CustomerSNsDBModel
    {
    public class CustomerVoiceCLI
    {
    public long id { get; set; }
    public long CustID { get; set; }
    }

    public class CustomerVoiceCLIPriceLists
    {
        public long id { get; set; }
        public long CustomerIndex { get; set; }
        public long CustomerVoiceCLIIndex { get; set; }
        public string PriceList { get; set; }
        public int PriceListType { get; set; }
        public int PriceListLevel { get; set; }
    }
    

    }

  • JS:

...
{ data: 'CustomerVoiceCLIPriceLists' ,
render: "[, ].PriceList",
className: 'text-left'
},
{ data: 'CustomerVoiceCLIPriceLists' ,
render: "[, ].PriceList",
className: 'text-left'
},
...

I'm getting an error in the server part 'An item with the same key has already been added.'. It seems to be because I'm using the same db field (PriceList) in both dt columns. How can I show values from identical db fields in 2 different dt columns? Thanks.

Answers

This discussion has been closed.