Quantcast
Channel: URF - Unit of Work & (extensible/generic) Repositories Framework
Viewing all articles
Browse latest Browse all 1539

Closed Unassigned: Saving or accepting changes failed because more than one entity of type have the same primary key value [1247]

$
0
0
My method is like this
```
public void InsertNormal(PurchaseHeader entity)
{


foreach (var purchaseDetail in entity.PurchaseDetails)
{


//Positive Side
var transactionPtv = new Transaction
{
TransactionId = Guid.NewGuid(),
Stack = 0,
Quantity = purchaseDetail.OrderQty,
QuantityInUnit = purchaseDetail.OrderQty,
TransactionDate = entity.PurchaseDate,
TransactionGroupId = transactionGroup.TransactionGroupId,
LedgerId = Ledger.GoodsOnHand,
StoreId = entity.StoreId,
ProductId = purchaseDetail.ProductId,
UnitId = purchaseDetail.UnitId,
ProductColor = purchaseDetail.ProductColor,
ProductSize = purchaseDetail.ProductSize,
PurchaseHeader = entity
};

//Negative Side
var transactionNtv = new Transaction
{
TransactionId = Guid.NewGuid(),
Stack = 0,
Quantity = -purchaseDetail.OrderQty,
QuantityInUnit = -purchaseDetail.OrderQty,
TransactionDate = entity.PurchaseDate,
TransactionGroupId = transactionGroup.TransactionGroupId,
LedgerId = Ledger.GoodsOnReceivable,
StoreId = entity.StoreId,
ProductId = purchaseDetail.ProductId,
UnitId = purchaseDetail.UnitId,
ProductColor = purchaseDetail.ProductColor,
ProductSize = purchaseDetail.ProductSize,
PurchaseHeader = entity
};


purchaseDetail.ObjectState = ObjectState.Added;



}

#endregion

base.Insert(entity);

//base.InsertOrUpdateGraph(entity);
}
```

PurchaseDetail is Collection found on PurhcaseHeader, but the following exception

Saving or accepting changes failed because more than one entity of type have the same primary key value. Ensure that explicitly set primary key values are unique. Ensure that database-generated primary keys are configured correctly in the database and in the Entity Framework model.

Viewing all articles
Browse latest Browse all 1539

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>