How to get Oracle next sequence value in .NET Entity Framework? -


i have web api post method inserts new row in table in oracle database. i'm having trouble primary key of table sequence value. how do my_primary_key_seq.nextval in entity framework? code works violate pk unique constrain when new row inserted via our old .net webform uses sequence next value next primary key.

decimal nextpk = context.formpps.orderbydescending(p => p.ppid).firstordefault().ppid + 1; item.ppid = nextpk; context.formpps.add(item); int result = context.savechanges(); 

i had same issue, , resolved site , oracle. i'm assuming you're using database first, since mentioned legacy app uses same database.

there few things had do. daniel gabriel mentioned, if allow oracle manage identity, don't need ever call sequence find out number, database takes care of you. getting work little tricky because may need make bunch of changes database.

  1. create sequence (you've done this) on identity column.

  2. create trigger automatically call sequence on insert. http://www.oracle-base.com/articles/misc/autonumber-and-identity.php

  3. alter entity framework model. using ef database first, , found article explained needed alter model set property of table's identity column

    storegeneratedpattern="identity"

oracle entity in vs entity framework doesnt update primary key in code

  1. but didn't fact had re-add change every time refreshed ef model database. double-click .edmx file, locate table in database diagram, highlight identity column in diagram, , in properties window, change storegeneratedpattern value identity. should make persist when update ef model.

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -