So, I have created a database where we have two objects, a Voucher and a Transaction. A voucher has a column to reference the bigint ID field in Transaction. There are also various fields in both tables that have a been writing to database correctly. But I'm having trouble getting the correct Transaction.ID number into the Voucher Record.
Using MS SQL Express, ASP.net Core 3.0.1, EntityFrameWork Core.
I've scaffold from Db. I've also, for good, measure, went into the context class's onModelCreating method and added ValueGeneratedOnAdd to the relevant properties.
I've created a Data Transfer object in an attempt to simplify and condense the creation of these two objects in one View.
What I'd like to know is if there is a means of adding the Transaction via _context.Add(), then obtaining the value generated ID to assign to the Voucher's "transaction reference" field before adding writing to the database.
If there is a simpler method, please educate me. Its important that we have two tables to separate.
I'm trying to understand the technique to apply larger/more complex scenarios.
Aucun commentaire:
Enregistrer un commentaire