locked
Validation helper class RRS feed

  • Question

  • Hi,

    I use the same validation code to check for duplicate strings throughout my application.  How do you create a generic helper class to perform a function like this for any entity string property?  I would like to call in validation method something like this:

    If (Not stringUnique) Then

    results.AddPropertyError("some message")

    EndIf

    The generic validation class would accept parameters for the entity, property, dataworkspace, etc. to perform the query/function??? This is where I'm stuck.  Thanks!

    Monday, October 28, 2013 1:48 PM

All replies

  • Hi Hessc,

    According to MSDN description, “By applying validation rules to an entity or table, you can ensure that properly formatted data is written to the data source for a Visual Studio LightSwitch application. A validation rule is a condition or constraint that the data in your application must comply with. If you can add one or more validation rules to an entity or table, an error appears if a user adds or changes data in a way that doesn't comply. Before a user can commit the data, the validation error must be fixed.”

    And we can apply predefinded validation to a field, apply custom validation rules to a field, apply custom validation rules to data in a screen and apply validation rules that run when data is saved.

    You can get more details from MSDN:

    How to: Validate Data in a LightSwitch Application

    http://msdn.microsoft.com/en-us/library/vstudio/ff852065(v=vs.110).aspx

    Adding Validation

    http://msdn.microsoft.com/en-us/library/vstudio/ff852045(v=vs.110).aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 29, 2013 8:59 AM
  • Hi Yunjie,

    Thank you for the general information regarding LS validation.  However, my question is about placing the custom validation logic in a separate class to make it reusable.  Thanks.

    Tuesday, October 29, 2013 1:29 PM
  • Hi Hessc,

    Do you want to know the common validation rules in Lightswitch? If so, I'd like to suggest you to refer to the blog written by Beth Massi:

    Common Validation Rules in LightSwitch Business Applications

    http://blogs.msdn.com/b/bethmassi/archive/2011/11/11/common-validation-rules-in-lightswitch-business-applications.aspx

    Hope it helps.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 30, 2013 1:14 PM
  • Yunjie,

    Thanks for your help but that is not the information I'm seeking.  I believe the folks that regularly contribute to this forum will understand what I am asking about based on the description provided.  My question is not about how LS validation works, but rather how to create a reusable generic class to perform common validation methods (e.g. check a string property for duplicates) so that I don't have to write the method in the table code for each of my entities.


    • Edited by Hessc Wednesday, October 30, 2013 8:14 PM
    Wednesday, October 30, 2013 8:13 PM