我遇到了nhibernate的情况。我有这段代码:
private void UnlinkProductsFromPriceAgreement(NameValueCollection collection, IUnitOfWork unitOfWork)
{
// Get the price agreement id
int priceAgreementId = collection.GetInt("Id");
foreach (int productId in collection.GetIds("unlinkProductsList"))
{
// Get the product price
IProductPrice productPrice =
ProductPriceRepository.Find(p => p.PriceAgreement.Id == priceAgreementId && p.Product.ProductId == productId).FirstOrDefault();
// Remove the product price
ProductPriceRepository.Delete(productPrice);
}
}
运行此代码时出现此异常:
Qe.Common.Core.Exceptions.PersistencyException ---> NHibernate.HibernateException: identifier of an instance of Qe.Vending.Core.DomainObjects.Product was altered from 210036 to 0
at NHibernate.Event.Default.DefaultFlushEntityEventListener.CheckId(Object obj, IEntityPersister persister, Object id, EntityMode entityMode) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\DefaultFlushEntityEventListener.cs:line 111
at NHibernate.Event.Default.DefaultFlushEntityEventListener.GetValues(Object entity, EntityEntry entry, EntityMode entityMode, Boolean mightBeDirty, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\DefaultFlushEntityEventListener.cs:line 84
这怎么可能?