This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, in my table (SQL Server) there are nvarchar(50) fields that are not nullable but can contain empty strings. If I drag this table on the designer, it generates validation attributes [ValidatePresence] and [ValidateLength(0, 50)] for these fields. This is not what I need because the [ValidatePresence] attributes don't allow empty strings. If I remove the [ValidatePresence] attribute the validation allows null values (but the database complains). What am I doing wrong? Thanks Andreas
|
|
|
Do you have any advice for me how I can handle strings that should allow empty but not null values? |
|
|
Hello Andreas, Sorry for the delay in getting back to you about this. I don't think this can currently be handled, so we'd need to provide an enhancement to support it (probably in the form of an option on ValidatePresence to say that "empty counts as present"). The reason that ValidatePresence currently rejects empty strings is that users generally don't distinguish between null and empty strings: therefore data binding frameworks typically treat them interchangeably (and will provide an empty string rather than a null to represent missing input), and so indeed do some databases (e.g. Oracle). So we'd normally recommend using a nullable column where empty data is acceptable; I realise that this does change the semantics but it may map better to user expectations. However, if you feel that's inappropriate for your scenario, and you really do need to distinguish between nulls and empties, let us know and we'll get you a fix. |
|
|
Hi Ivan,
thanks for your response. In the sense of the UI part of applications I'm absolutely with you, there I can treat empty strings as missing inputs. But I use the same data layer for importing data from an external source. And in that source empty strings are valid while nulls are not. So I would loose the possibility to check for valid entries if I'd declare those fields as nullable. Not a big deal, just a few lines of extra code. But I would definitely be very pleased about a fix :-) |
|
|
Okay, I have added an AllowEmptyStrings option to ValidatePresenceAttribute. This defaults to false, but can be set to true to allow empty strings to count as present. This will be included in nightly builds dated 8 August 2009 and above, available from about 1430 GMT. Please let us know if you run into any problems. |
|
|
works perfectly, thanks a lot.
|
|