Skip to content

"required fields" don't allow empty string #78

@RajNZ

Description

@RajNZ

If a model has what Breeze considers to be a "required field" string property (so far I have encountered key properties and TPH discriminator properties; in fact it will be any string property that is not nullable) then Breeze does not allow the value of the property to simply be empty string ("") - it generates a validation error :

'MyProperty' is a required field

We recently changed from using Breeze.Sharp.Standard.Fork (it came with the Blazor project template we use) to Breeze.Sharp 0.9.1. This was not a problem in Breeze.Sharp.Standard.Fork but is a problem in Breeze.Sharp.

Oddly, for some properties we get the error even if, at the time of saving, the property does contain a non-empty value; in this case the problem arises if the dto that we are saving was not initialised with a non-empty string set for the property, even if the property is set to something afterwards. The fix for this situation is to initialise the property to " " or similar.

I can remedy the problem by ensuring that all such properties both contain a non-empty value and are initialised with a non-empty value, but this is a real drag...

Is this behaviour intentional in Breeze.Sharp, or something unintended?

This is my example of a property, UMID, that is simply a non-nullable string and Breeze.Sharp 0.9.1 insists that it cannot be empty string "".

Data model

public partial class DATAMfgBomHeaderArticle
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ArticleID { get; set; }

    [StringLength(10)]
    [Unicode(false)]
    public string UMID { get; set; }

      // many more properties...
}

DTO

public partial class DATAMfgBomHeaderArticle : BaseEntity
{
    
    [Key]
    public Int32 ArticleID
    {
        get { return GetValue<Int32> (); }
        set { SetValue(value); }
    }
    public String UMID
    {
        get { return GetValue<String> (); }
        set { SetValue(value); }
    }

   // many more properties...
}

Run this code

 DATAMfgBomHeaderArticle newItem = new DATAMfgBomHeaderArticle();
 newItem.UMID = "";
entityManager.AddEntity(newItem);
await entityManager.SaveChanges();

and it produces a validation error when attempting SaveChanges().

Image

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