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

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

Postby David9 » Tue 10 Jul 2012 13:02

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.
David9
 
Posts: 2
Joined: Tue 10 Jul 2012 12:27

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

Postby MariiaI » Thu 12 Jul 2012 07:56

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.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to dotConnect for Oracle