c# - Auto Increment ID in Composite key Entity Framework -


i have 2 class these

public partial class master {         [key, column(order = 0)]         public int idmaster { get; set; }         /*more fields*/ }   public partial class detail {         [key, column(order = 0)]         public int idmaster { get; set; }          [key, column(order = 1)]         [databasegenerated(databasegeneratedoption.identity)]         public int id { get; set; } } 

i want auto-increment id in way:

|----------|-----------| |masterid  | id        | ------------------------ |         1|          1| |         1|          2| |         1|          3| |         1|          4| |         2|          1| |         2|          2| |         2|          3| |         2|          4| ------------------------ 

how can in entity framework

a lot of help

edit: have want increment id mentioned:

|----------|-----------| |masterid  | id        | ------------------------ |         1|          1| |         1|          2| |         1|          3| |         1|          4| |         2|          5| |         2|          6| |         2|          7| |         2|          8| ------------------------ 

i know can via code wanted know if there way it.

if can, use trigger in database.

-- tsql in sql server 2008+ create trigger tr_detail_autoidentity on detail instead of insert begin   insert detail(idmaster, id)    select inserted.idmaster, isnull((select max(id) detail idmaster = inserted.idmaster), 0) +  row_number() on (partition idmaster order id)  inserted end --i love one, work multiline insert. may need lock multiuser, i'm not sure. 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -