-
Notifications
You must be signed in to change notification settings - Fork 35
Description
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().
