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 whendescription = null
(having no value)?
this appears symptom of entity framework.
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
Post a Comment