Replies: 3 comments
-
The CSLA property implementation for Does your business logic need to differentiate between "" and null? Or is that just some artifact of a database designer making an arbitrary choice? Usually a db uses null to differentiate between a value that was never entered by the user, vs "" which is a valid empty value entered by the user. Not everyone gets that this is the purpose of null, so there's a lot of weird stuff out there. |
Beta Was this translation helpful? Give feedback.
-
We manage this discrepancy between UI vs. database by using a DBValue extension method within our data portal methods. We enforce usage through code reviews, but we have considered a custom analysis rule to detect direct assignment of strings to database parameters instead of using the DBValue method. |
Beta Was this translation helpful? Give feedback.
-
Hello @rockfordlhotka and @hurcane, Basically, the SQL check constraints does distinguish between null and "". If the value is null for the column, then the check is bypassed but it has a value "" or anything else the check is verified and "" fails the check. Basically, I wanted to see if I could get away from doing something like this on the Business Edit object Update method. tReTransmitEngID = string.IsNullOrEmpty(tReTransmitEngID) ? null : tReTransmitEngID, or this on the Dal object old.tReTransmitEngID = string.IsNullOrEmpty(data.tReTransmitEngID) ? null : data.tReTransmitEngID;
The both of the above sample lines work. I just implemented the one on the business edit update method. |
Beta Was this translation helpful? Give feedback.
-
Hello,
Is there a secrete to converting a edit object property value of type string which is Empty.String to null before I save to the database?
Reason: There is a sql check constraint that will fail with the saved value is Empty.String but when its null its okay.
I have added nullable value for the property type on the Edit object and the Info object but when it saves to the database its still Empty.String and not null.
Beta Was this translation helpful? Give feedback.
All reactions