From: paul.mercea <pau...@al...> - 2017-08-25 20:52:18
|
The trigger from you database has nothing to do with your c# code.You can use a stored procedure to insert data and returning latest id (also you can read current sequence value but you can have wrong value if other inserts happening). Sent from my Samsung Galaxy smartphone. -------- Original message --------From: "Mr. John via Firebird-net-provider" <fir...@li...> Date: 8/25/17 20:28 (GMT+02:00) To: "For Users and Developers of the Firebird .NET Providers" <fir...@li...> Cc: "Mr. John" <mr_...@ya...> Subject: [Firebird-net-provider] EF - last inserted ID is 0 HiI'm using FB 2.5,EF Firebird 5.9.1,Asp MVC 5 with VS 2017 on a table I have a trigger to generate ID: CREATE OR ALTER TRIGGER TRIG_MYTABLE_BI FOR MYTABLE ACTIVE BEFORE INSERT POSITION 0 AS BEGIN IF ((NEW.ID IS NULL) OR (NEW.ID=0)) THEN NEW.ID=NEXT VALUE FOR GEN_MYTABLE_ID; END in my code I insert data like this: myTableEnt newRec= new myTableEnt() { NAME='MYNAME', .... }; db.myTableEnt.Add(newRec); db.SaveChanges(); return ToJson(new { msg = newRec.ID.ToString() }); newRec.ID is returned always 0,but in database value is generatedwhat I've done wrongthanks |