vb.net - “A cycle was detected in the set of changes” with Linq to SQL -


i developing application in experience exception "a cycle detected in set of changes" when calling datacontext.submitchanges(). know why exception thrown have not been able find fix situation. let me explain situation. have database table shown below access linq sql gets mapped classes in vb.net.

device ------- id defaultgatewayid 

the defaultgatewayid device can same object or device. user uses gui datagrid alter , add new records. updating records no problem. id exists , defaultgatewayobject attached record (the id stored in database).

however when try add new record , set defaultgatewayobject in same transaction 'cycle detected in set of changes'-exception. suspect caused linq sql because not know record add first, although same item in case.

i not have option break insertion 2 parts, 1 device , adding defaultgateway because submit button bound xaml command executes submitchanges.

ideally have option specify object created first, or that. think it's option remove connection , set id in field, i'd rather find fix within linq sql.

i hope has answer this. find related post "cycle detected while adding circularly linked list"

you can break insertion 2 parts ans still have 1 transaction if wrap code in transactionscope.

using trans new transactionscope()     'code generates new id in database     dc.submitchanges()      'code uses new id value.     dc.submitchanges()      trans.complete() end using 

this way avoid exception. if impossible because of architectural decisions ("my submit button bound xaml command") need change architecture. think ui command should never close data access layer anyway. better call service method xaml.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -