Inserting a record on a joined table / Editor with C# .Net

Inserting a record on a joined table / Editor with C# .Net

JamesGoodJamesGood Posts: 1Questions: 1Answers: 0
edited November 2020 in Free community support

Hello,

I have started using Editor to build a UI onto a basic Product table (SQL Server DB), and a joined Details table.

It's working beautifully for editing. I can view and edit data in both tables.

However, when I try and create a new record, the record for the main Products table gets created, but the joined table entry does not get created.

The one bit of complexity in this situation is that the Products table primary key (ProductsTableID), is not the join element (ProductID).

var editor = new Editor(db, "products", "ProductsTableID")
.Model<ProductsModel>("products")
.Model<DetailModel>("detail")
.LeftJoin("detail", "detail.ProductID", "=", "products.ProductID");

My question: I was hoping Editor would do the creation of the joined table row automatically. Is that not the case? Do I need to manually create the joined record.

Thanks,

-James.

Answers

  • allanallan Posts: 63,192Questions: 1Answers: 10,412 Site admin

    Hi James,

    It is semi-possible... This is the bit of code can governs that. The main issue though is that you need to submit the primary key for the linked table - that obviously doesn't work if it is auto-generated though.

    Unfortunately Editor wasn't really designed with this use in mind - typically we suggest creating a table the detail database table, where you can manage the details, and then use a left join to select the entry in the products table.

    Sorry I don't have better news on this one,
    Allan

This discussion has been closed.