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" 
<[email protected]> Date: 8/25/17  20:28  (GMT+02:00) 
To: "For Users and Developers of the Firebird .NET Providers" 
<[email protected]> Cc: "Mr. John" 
<[email protected]> 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
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Firebird-net-provider mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to