silverlight - RIA/EF4 Entity property mapped to NOT NULL nvarchar - empty string -


background:

  • entity framework 4
  • silverlight 4
  • ria services
  • mssql server 2008

i have entity has string property named description.

in database maps not null nvarchar(200).

problem:

when try insert new row of entity, do:

myexampleentity entity = new myexampleentity() {     name = "example",     description = ""        // note line! };  databasecontext db = new databasecontext(); db.myexampleentities.add(entity); db.submitchanges(); 

this, however, causes exception saying "the description field required."

question:

should not "empty string" - a string 0 characters?

i believe description = null should treated providing no value.

  • why string, has value (although length 0), considered if have omitted value?
  • on level conversion happen? on ria, on ef or in mssql?
  • is there way make description have zero-length value when set description "" , cause exception when description = null (having no value)?

this appears symptom of entity framework.

related article

some data annotations can used overcome this:

[metadatatype(typeof(report_meta))]    public partial class report    {    }     public partial class report_meta    {        [required(allowemptystrings = true)]        [displayformat(convertemptystringtonull = false)]        public object note { get; set; }      } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -