Friday, August 12, 2011

NHibernate and Entity Framework error details

Sometimes, NHibernate produces clearer error message than Entity Framework.

Entity Framework, level of error detail is sounding like an alibi:

Test method TestProject.TestTheIRepository.Ef_CanUpdate threw exception: 
System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. See the InnerException for details. ---> System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Invalid column name 'Product_ProductId'.

While NHibernate is very spot-on from where the error came from:

Test method TestProject.TestTheIRepository.Nh_CanUpdate threw exception: 
NHibernate.Exceptions.GenericADOException: could not insert: [TestProject.SampleModel.ProductPrice][SQL: INSERT INTO [ProductPrice] (EffectiveDate, Price, Product_ProductId) VALUES (?, ?, ?); select SCOPE_IDENTITY()] ---> System.Data.SqlClient.SqlException: Invalid column name 'Product_ProductId'.

Check your Entity Framework mapping or your database, e.g. see if the mapped column on your Entity Framework class' property is existing on your database table.

No comments:

Post a Comment