Page 1 of 1

Can not insert entity with the same key if key is not database generated

Posted: Tue 10 Jul 2012 13:02
by David9
Hi everyone,

I'm having trouble when I want to insert a new registry in the database. My application throws that exception:

System.InvalidOperationException: Can not insert entity with the same key if key is not database generated.

The code is:

Code: Select all

stock = new Stock();                            stock.MasterProduct = _dataContext.MasterProducts.Single(mp => mp.MpReference == reference);                            stock.StBatch = batch;                            stock.Transportunit = _dataContext.Transportunits.Single(t => t.Barcodelabel == tuBarcode);                            stock.StDate = (bbd.HasValue)                                               ? bbd.Value                                               : (packedDate.HasValue) ? packedDate.Value : bbd.GetValueOrDefault();                            stock.StBbdd = bbd;                            stock.StPackagingd = packedDate;                            stock.StQuantity = quantity;                            stock.StockState = _dataContext.StockStates.Single(s => s.SsId == (int)StockStateEnum.Available);                            stock.StOrigin = origin;                            stock.Quarentined = isQuarentined ? 1 : 0;                            stock.Warehouse = _dataContext.Warehouses.Single(w => w.Warehouseid == warehouseId);                            stock.StUnitservice = unitsService;                            stock.Internalorderid = internalOrderId;                            stock.Orderlineid = orderLineId;                             _dataContext.Stocks.InsertOnSubmit(stock);                     _dataContext.SubmitChanges();
I don't know what happens... I'm using the 5.7 version.
Thanks in advance.

Re: Can not insert entity with the same key if key is not database generated

Posted: Thu 12 Jul 2012 07:56
by MariiaI
Unfortunately, we cannot reproduce the issue in our environment using dotConnect for Oracle 7.0.25 version. Please try updating the version of your dotConnect for Oracle to the latest one and notify us about the results.

If it doesn't help, please specify the following:
- the definitions of the entity classes, that are used in your code (e.g., MasterProducts, Transportunits, Stocks);
- the associations between these classes.

If possible, please send us the model you are working with or a sample project, so that we are able to reproduce and fix this issue.
Looking forward to your reply.