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

  • Home
  • SEARCH
  • 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 886567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:05:24+00:00 2026-05-15T13:05:24+00:00

If I have a dbml file that contains say a Customer class with say

  • 0

If I have a dbml file that contains say a Customer class with say a single property of CompanyName;

public partial class Customer : INotifyPropertyChanging, INotifyPropertyChanged
private string _CompanyName;
public string CompanyName
{
  get

Now, given that the above is in a dbml and thus generated I obviously should avoid editing it like the plague.

So I have created another class like so;

public partial class Customer
{
    [Required]
    public string CompanyName{get;set;}
}

The reason for this is because I want to decorate my field as being required.

However this doesn’t work as I get the compile error “…already contains a definition for ‘CustomerID'”.

Does anyone know a way around this or is there a better way to mark fields as required or of validating a model?

  • 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-15T13:05:25+00:00Added an answer on May 15, 2026 at 1:05 pm

    The solution is to use a MetadataType attribute with an additional class that contains the data validation annotations.

    See: http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a partial class in a dbml file. public partial class Comment string
I have the following 3 classes in my dbml file: public class Player {
I have a .dbml file which of course contains the auto-generated classes based on
I have a rather large DBML file and recently discovered that Visual Studio's MSLinqToSQLGenerator
I have a class reflecting my dbml file which extends DataContext, but for some
I have a dbml file that was autogenerated. I want to, in code (VB.Net)
I have class Company that having the property Departments as list (List). Having fields:
I am using Visual Studio 2010, and I have a LINQ-to-SQL DBML file that
This is how i have it setup: DAL: a dbml file for the context
I have added a table(ViolationsDataSourceConfig) to the dbml file. The context name is ViolationsDataContext.

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.