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.
```
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.