none
EF5 RC is not handling nullable database fields properly; Bug? RRS feed

  • Question

  • Hello,

    Entity Framework 5RC + ASP.NET 4

    I have a table with the following field in it:

    Editor nvarchar(200) nullable

    I generated a new EF model in my application and generated POCO entities using "Add Code Generation Item..." on the model's diagram.  I saved the changes, I cleaned my solution, and I rebuilt the entire solution.  When I run my application and try to add or edit this kind of entity, EF5RC reports that

    "Cannot insert the value NULL into column 'Editor', table '@T'; column does not allow nulls. INSERT fails.
    The statement has been terminated."

    The database table field is nullable.  I returned to the model and examined this field in the entity.  Its "Nullable" is set to "(None)", which is odd.  I would have expected it to be True.  I set it to True, saved the model's changed, cleaned the solution, and rebuilt the entire solution.  When I ran the application, I receive the same error.  The only way that I can seem to get around this issue is to set this field to some junk value in my MVC Controller. 

    In my ViewModel, this field is not being passed to the Create or Edit actions, so data annotations and "Required" are not an issue.

    In my Entity Framework "Domain" project, this field is annotated as follows for a "Customer" entity...  Note that it is not set as Required.

    --------------------------
    [Display(Name = "Title_Editor", ResourceType = typeof(Resources))]
    [StringLength(200, ErrorMessageResourceName = "Error_200CharactersOrLess", ErrorMessageResourceType = typeof(Resources))]
    public string Editor { get; set; }
    --------------------------

    I've tried to delete my entity from the model, clean the solution, recreate the entity and POCO class, but this issue persists.

    This looks like an EF5RC bug to me...  Has anyone else encountered it?  How do I report it to the EF Development Team?

    Thanks,

    Mike

    *********************** EXCEPTION MESSAGE ************************
    System.Data.Entity.Infrastructure.DbUpdateException was caught
      Message=An error occurred while updating the entries. See the inner exception for details.
      Source=EntityFramework
      StackTrace:
           at System.Data.Entity.Internal.InternalContext.SaveChanges()
           at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
           at System.Data.Entity.DbContext.SaveChanges()
           at ExpirationTrax.Domain.Repositories.EFCustomerRepository.Update(BaseCustomer customer) in C:\PROJECTS\ExpirationTraxMVC\ExpirationTrax.Domain\Repositories\EFCustomerRepository.cs:line 49
      InnerException: System.Data.UpdateException
           Message=An error occurred while updating the entries. See the inner exception for details.
           Source=System.Data.Entity
           StackTrace:
                at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
                at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
                at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
                at System.Data.Entity.Internal.InternalContext.SaveChanges()
           InnerException: System.Data.SqlClient.SqlException
                Message=Cannot insert the value NULL into column 'Editor', table '@T'; column does not allow nulls. INSERT fails.
    The statement has been terminated.
                Source=.Net SqlClient Data Provider
                ErrorCode=-2146232060
                Class=16
                LineNumber=42
                Number=515
                Procedure=CustomersHistoryTrigger
                Server=DevPC\SqlExpress
                State=2
                StackTrace:
                     at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
                     at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
                     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
                     at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
                     at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
                     at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
                     at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
                     at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
                     at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
                     at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
                     at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
                InnerException:


    Thursday, August 23, 2012 9:05 PM

Answers

  • Hi Mike,

    It looks like there is a trigger on the table you are editing that is inserting data into another table, that table does not allow nulls on the Editor column.


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Friday, August 24, 2012 9:06 PM
    Moderator

All replies

  • Hi,

    You can send bugs to the EF team via the issue tracker on the codeplex site here: http://entityframework.codeplex.com/

    Alternatively I could raise the issue for you, but I would have to reproduce it first. Do you have a solution that reproduces the problem that you can send to me? If not then I can try and put one together myself, but it might take a while.

    If you want to send me a solution then you can send it to glennc 'AT' Microsoft 'dot' com. Otherwise feel free to attach a solution that reproduces it to an issue on codeplex if you want and the team will talk to you about it at some point.


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Friday, August 24, 2012 5:02 PM
    Moderator
  • Hi Glenn,

    I'd be happy to send the solution to you so you can directly see what I am seeing.  I will send it to your e-mail today.

    Thanks,

    Mike

    Friday, August 24, 2012 5:32 PM
  • Hi Mike,

    It looks like there is a trigger on the table you are editing that is inserting data into another table, that table does not allow nulls on the Editor column.


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Friday, August 24, 2012 9:06 PM
    Moderator