i new programming. familiarize myself f# , sql server, decided try implementing code found here. have pasted below convenience of not want click on link:
let newrecord = new dbschema.servicetypes.table1(id = 100, testdata1 = 35, testdata2 = 2.0, name = "testing123") let newvalues = [ in [1 .. 10] -> new dbschema.servicetypes.table3(id = 700 + i, name = "testing" + i.tostring(), data = i) ] // insert new data database. db.table1.insertonsubmit(newrecord) db.table3.insertallonsubmit(newvalues) try db.datacontext.submitchanges() printfn "successfully inserted new rows." | exn -> printfn "exception:\n%s" exn.message
i created 2 tables, named table1 , table 3, in sql server. initially, set primary key in each table id. running code above returned output:
exception: cannot add entity key in use.
i started randomly trying various ways of resolving issue (bad practice, know!), based on information found googling exception. 1 approach took change primary key in each table "name" instead. time, no exception thrown.
my problem solved, not understand how or why. questions are:
- why exception thrown initially? did have fact set "id" primary key?
- did fact change primary key "name" eradicate error? if so, how , why did make difference?
thanks in advance help. please let me know if question insufficiently detailed.
this looks should work - id should unique.
here debug pointers:
get raw interface sql can type queries yourself.
make sure table empty before run code.
- test system typing in raw sql in sql client see if works.
good luck.
Comments
Post a Comment