Hiit seems to work only if I go to edmx,on ID filed and set 
StoreGeneratedPatern = Identitybut I use  DbFirst and this could be replaced on 
model update from dbI've tried using partial class with no success
in my model generated code I have something like this:namespace POSweb.Models
{
     
    public partial class GS_POS_CO
    {
.....    
        public long ID { get; set; }
.....
    }
}I've added a new file to my project, Annotations.cs and inside a new partial 
class with the same name for class and namespace:
namespace POSweb.Models
{

    [MetadataType(typeof(GS_POS_CO.Annotations))]
    public partial class GS_POS_CO
    {
      internal class Annotations
      {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long ID { get; set; }
      }
    }
} 


thanks for any help





From: Jiří Činčura <j...@cincura.net>To: 
"firebird-net-provider@lists.sourceforge.net" 
<firebird-net-provider@lists.sourceforge.net>Sent: Sunday, August 27, 2017, 
6:16:03 PM GMT+3Subject: Re: [Firebird-net-provider] EF - last inserted ID is 0
Your myTableEnt should have Id marked as DatabaseGen…Options.Identity. Then 
it's fetched back automatically. 

--
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/


On Fri, Aug 25, 2017, at 19:28, Mr. John via Firebird-net-provider wrote:
> 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

------------------------------------------------------------------------------
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
------------------------------------------------------------------------------
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