0

I used Code First to create 2 tables (Master and Details), the problem is that Entity Framework inserted the same Generator for both tables, so when I insert a new record the trigger skips the ID numbering (1,3,5... for Master and 2,4,6... for Details) What I want is: Master ID equals 1,2,3... and Details ID equals 1,2,3... I know how to correct it in the database is just to add a new genarator and correct both triggers with the respective Generators, but how to avoid it when using Code First, is there a way to use Data Annotations in the classes? or are there another way to do it?

enter image description here

Arioch 'The
  • 15,799
  • 35
  • 62
  • one article uses this: `[Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int INVOICE_ID { get; set; }`, sadly it does not mention why, so i suspect the bug in .Net Provider https://habr.com/ru/post/278405/ Maybe try asking on the maillist at https://stackoverflow.com/tags/firebird-.net-provider/info // what is the generator name, maybe there is some hint in it ? – Arioch 'The Feb 19 '20 at 13:49
  • generator is the autoincrement in the primary key (Id), everytime I insert a new record in the database it automaticaly increment the Id – Fernando Donizeti Ito Feb 19 '20 at 13:52
  • 1
    the article also shows a special ad hoc EF extension to work with generators, and says there already is such for EF5 // autoincremented fields were only introduced in Firebird 3, and they are not considered generators on SQL level. Firebird 2 does not have auto-inc fields – Arioch 'The Feb 19 '20 at 13:53
  • exactly, that is why EF implement triggers to the database, if(new.id is null) then new.id = next value for gen_identity; the problem is this gen_identity that was created for both tables, the correct would be gen_identity_sales and gen_identity_salesItems for example – Fernando Donizeti Ito Feb 19 '20 at 14:13
  • Maybe there is an optional parameter to `[DatabaseGenerated` or to `[Key` attribute, specifying "table name" part of generator ? The part which is empty string by default... Also note, you can not always just concatenate table name to fixed prefix, cause you might run above maximum identifier length. That said, why should this realyl be a problem? Generators never warranted columns being filled with no gaps in them, it is not their intention. The only difference is "few gaps here and there" vs "gap after every row", but is that really than important? – Arioch 'The Feb 19 '20 at 14:20
  • With [DatabaseGenerated(DatabaseGeneratedOption.None)] didn't work too. – Fernando Donizeti Ito Feb 19 '20 at 17:35
  • 1
    I'd recommend asking on the [firebird-net-provider Google Group/mailing list](https://groups.google.com/forum/#!forum/firebird-net-provider) instead. You're more likely to get an answer there. – Mark Rotteveel Feb 19 '20 at 18:08

1 Answers1

2

You can customize the behavior using IFbMigrationSqlGeneratorBehavior. You can also get a head start by using DefaultFbMigrationSqlGeneratorBehavior.

cincura.net
  • 4,130
  • 16
  • 40