I'm new to silverlight and therefore data access in silverlight so bear with me. I have an ADO.Net entity data model referencing a sql server 2008 database. The table causing problems is called transaction. The transaction table has a non-nullable field "MerchantChain". This table is populated by another program that inserts empty strings into the merchantchain field when a merchant chain is not supplied. So in my silverlight app I load a grid with transactions based on criteria supplied by the user. The grid is for display only, but I need to be able to update the status of a transaction after a user views it. So I set the transaction.status field and attempt a submitchanges. Before submitchanges, the transaction.HasValidationErrors is false. As soon as the submitchanges is executed (in the debugger) the HasValidationErrors is true and the submit throws an unhandled exception. The ValidationError is that the merchantchain field is required. Well, its an empty string - its not null. No idea what to do. This is visual studio 2010, silverlight 4, vb.net.
+1
A:
[Required(AllowEmptyString = true)]
You need to make the empty string allowed. Go to your buddy class and add this. More detail can be found here:
JosephC
2010-05-16 16:42:13
Thanks - worked like a champ! For the VBers its the [DomainServiceName].metadata.vb file. And the syntax is <Required(AllowEmptyStrings:=True)>
Bob
2010-05-17 14:45:31
It's just me or MS could have done a lot better here?
Nelson Reis
2010-05-29 17:50:11
I'm not quite sure what you mean. I'm guessing you mean not requiring the AllowEmptyString. Validation is enforced based on the RequiredAttribute. If there was a required field bound to a textbox I would want my validation to require the user to enter text into it unless I specifically allowed it. The hard part is that RIA infers these attributes from the database. So the db designer marked a string field 'not null' so by default RIA assumes 'not empty string' as well. The idea behind it being, if I see [Required] I expect the user to have to enter SOMETHING.
JosephC
2010-06-26 18:31:02