Skip to content

InvalidOperationException: 'Field cannot be a zero-length string' on SaveChanges() #310

Backlog

Description

@OJacot-Descombes

Version: EntityFrameworkCore.LibRed 11.0.0-beta.1
TargetFramework: net11.0-windows

Problem
I have a string property of an entity class bound to a WinForms TextBox. TextBox.Text yields an empty string when it is empty. When calling SaveChanges() I get this exception with a nested exception:

Microsoft.EntityFrameworkCore.DbUpdateException
  HResult=0x80131500
  Message=An error occurred while saving the entity changes. See the inner exception for details.
  Source=Microsoft.EntityFrameworkCore.Relational
  StackTrace:
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
   at EntityFrameworkCore.Jet.Update.Internal.JetModificationCommandBatch.Execute(IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList`1 entries)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList`1 entriesToSave)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(StateManager stateManager, Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<>c.<SaveChanges>b__115_0(DbContext _, ValueTuple`2 t)
   at EntityFrameworkCore.LibRed.Storage.Internal.LibRedExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
   at ... my own code

  This exception was originally thrown at this call stack:
    LibRed.Engine.Execution.StatementExecutor.EnforceRequired(string, System.Collections.Generic.IReadOnlyList<LibRed.Catalog.ColumnDef>, object[])
    LibRed.Engine.Execution.StatementExecutor.UpdateRow(LibRed.Storage.Table, LibRed.Storage.RowId, object[], object[], System.Collections.Generic.Dictionary<(int Tdef, LibRed.Storage.RowId Id), object[]>, bool)
    LibRed.Engine.Execution.StatementExecutor.Update(LibRed.Sql.Ast.UpdateStatement)
    LibRed.Engine.Execution.StatementExecutor.ExecuteUpdate(LibRed.Sql.Ast.UpdateStatement)
    LibRed.Engine.Execution.StatementExecutor.Execute(LibRed.Sql.Ast.SqlStatement)
    LibRed.Engine.QueryEngine.ExecuteWritingStatement.__Run|21_0(ref LibRed.Engine.QueryEngine.<>c__DisplayClass21_0)
    LibRed.Engine.QueryEngine.ExecuteWritingStatement(LibRed.Sql.Ast.SqlStatement, System.Collections.Generic.IReadOnlyDictionary<string, object>)
    LibRed.Engine.QueryEngine.Route(LibRed.Sql.Ast.SqlStatement, System.Collections.Generic.IReadOnlyDictionary<string, object>)
    LibRed.Engine.QueryEngine.ExecuteCore(LibRed.Sql.Ast.SqlStatement, System.Collections.Generic.IReadOnlyDictionary<string, object>)
    LibRed.Engine.QueryEngine.Execute.AnonymousMethod__0()
    ...
    [Call Stack Truncated]

Inner Exception 1:
**System.InvalidOperationException:** 'Field 'Suppliers\.Fax' cannot be a zero\-length string\.'

Possible solution: Probably, empty strings should be converted to null by LibRed when saving.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions