Hi.Thanks Paul for your answerFor my first code I've followed this: 
https://stackoverflow.com/questions/4068084/how-to-find-an-identity-of-the-last-inserted-row-in-entity-frameworkand
 that seems not to apply to FB?I so I can insert ID without trigger,directly 
from my code,something like this:
  myTableEnt   newRec= new myTableEnt()                {  ID= 
GetNextSequenceValue(ref db, "SELECT NEXT VALUE FOR GEN_MYTABLE_ID FROM 
RDB$DATABASE")                    NAME='MYNAME',                    ....        
         };
...public long GetNextSequenceValue(ref myEnt ctx, string sql)        {         
    var rawQuery = ctx.Database.SqlQuery<long>(sql);            var task = 
rawQuery.SingleAsync();            long nextVal = task.Result;            
return nextVal;        }

thanks


From: paul.mercea <paul.mer...@almexa.ro>To: For users and developers of the 
Firebird .NET providers <firebird-net-provider@lists.sourceforge.net>Cc: Mr. 
John <mr_joh...@yahoo.com>Sent: Friday, August 25, 2017, 11:35:11 PM 
GMT+3Subject: Re: [Firebird-net-provider] EF - last inserted ID is 0
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" 
<firebird-net-provider@lists.sourceforge.net> Date: 8/25/17 20:28 (GMT+02:00) 
To: "For Users and Developers of the Firebird .NET Providers" 
<firebird-net-provider@lists.sourceforge.net> Cc: "Mr. John" 
<mr_joh...@yahoo.com> 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
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to