Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6906445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:18:38+00:00 2026-05-27T08:18:38+00:00

Taking the database first approach in MVC3 all of my models are created and

  • 0

Taking the database first approach in MVC3 all of my models are created and stored in a designer.cs

In the code below, I want to force a regex validation of the NDC property. The input needs to resemble 1234-1234-12 or 4 digits a dash 4 digits a dash 2 digits.

public partial class Drug : EntityObject

{
    #region Factory Method

    [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
    [DataMemberAttribute()]
        public global::System.String NDC
    {
        [Required(ErrorMessage = "Please enter the Rx NDC")]
        [RegularExpression(@"\d\d\d\d-\d\d\d\d-\d\d", ErrorMessage = "Please enter a correctly formatted NDC")]

        get
        {
            return _NDC;
        }
        set
        {
            if (_NDC != value)
            {
                OnNDCChanging(value);
                ReportPropertyChanging("NDC");
                _NDC = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("NDC");
                OnNDCChanged();
            }
        }
    }I dont know how to apply the code above in the code below because I get the this error:

Error 13 Attribute ‘Required’ is not valid on this declaration type. It is only valid on ‘property, indexer, field, param’ declarations. C:\Users\Daniel\Desktop\320Final -Updated\320Final\Models\DBModel.Designer.cs

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:18:39+00:00Added an answer on May 27, 2026 at 8:18 am

    You’re trying to set the attributes inside of the property:

    public global::System.String NDC
    {
        [Required(ErrorMessage = "Please enter the Rx NDC")]
        [RegularExpression(@"\d\d\d\d-\d\d\d\d-\d\d", ErrorMessage = "Please enter a correctly formatted NDC")]
        get
        {
            return _NDC;
        }
    ...
    

    You need to set them on the property itself:

    [Required(ErrorMessage = "Please enter the Rx NDC")]
    [RegularExpression(@"\d\d\d\d-\d\d\d\d-\d\d", ErrorMessage = "Please enter a correctly formatted NDC")]
    public global::System.String NDC
    {
        get
        {
            return _NDC;
        }
    ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to connect database to iphone sdk but it is taking the default
I am delving into the EntityFramework 4 code first of entities approach and I
I am new to EF using EF4 with Database First and generation taking place.
I'm taking the database that I created with SQL server express and putting it
First of all im relatively new to the Database world, Im graduating with my
When taking a database from a relatively un-normalized form and normalizing it, what, if
I have had experiences of Reverse engineering and people taking access of your Database
I am going over a past paper for a database course I am taking
Taking out all of the obvious caveats related to benchmarks and benchmark comparison, is
Here's the question first: Is this possible? I'm taking my inspiration from Joe Wrobel's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.