Custom Validation in ENTITY FRAMEWORK Dynamic Data Web App

Last post 01-05-2009 3:15 PM by marcind. 1 replies.

Sort Posts:

  • Custom Validation in ENTITY FRAMEWORK Dynamic Data Web App

    01-05-2009, 1:48 PM
    • Member
      1 point Member
    • mchatter
    • Member since 11-25-2008, 2:09 PM
    • Posts 23

     I'd like to do some custom validation in a Dynamic Data ENTITY FRAMEWORK application similar to the following:-

     

    if (ForeignKeyField = "A") { if (TextFieldA = "") { show error 'you must enter a value for field A'  } }

    if (ForeignKeyField = "B") { if (TextFieldB = "") { show error 'you must enter a value for field B'  } }

    if (ForeignKeyField = "C") { if (TextFieldC = "") { show error 'you must enter a value for field C'  } }

    etc.

     

    Can anyone point me in the right direction with links to existing examples or sample code ?

     

    Thanks in Advance !

  • Re: Custom Validation in ENTITY FRAMEWORK Dynamic Data Web App

    01-05-2009, 3:15 PM
    Answer
    • Contributor
      2,024 point Contributor
    • marcind
    • Member since 09-06-2007, 1:11 AM
    • Redmond, WA
    • Posts 410

    If I understand your question correctly, you can already do this by annotating your model using RequiredAttribute (note, you can customize the error message using the attribute's properties). Read How to: Customize Data Field Validation in the Data Model for a walkthrough.

    If this does no address your scenario, please clarify what you are trying to do.

    Marcin Dobosz
    SDE, ASP.NET Team, Microsoft
    Read my blog
Page 1 of 1 (2 items)