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 6867177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:16:37+00:00 2026-05-27T03:16:37+00:00

I have picked LINQ to SQL as ORM framework for ASP .NET MVC3 project.

  • 0

I have picked LINQ to SQL as ORM framework for ASP .NET MVC3 project. Everything was good before I was faced with need to put additional field ‘Confirm Password’ to registration form. As it was mentioned in one question on SO (unfortunately I can’t find it at the moment), it’s better to use interface to extend generated LINQ to SQL classes with validation attributes, instead of having another class for storing validation attributes. So here we go:

public interface IRegTry
    {
        [Required]
        [Email]
        string EMail { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "Should not exceed 100 symbols")]
        string FirstName { get; set; }

        [Required]        
        string Password { get; set; }        

    }

    [MetadataType(typeof(IRegTry))]
    public partial class RegTry : IRegTry { }

RegTry class is generated class by LINQ to SQL based on database entity.

On the View we have confirm password field, which should make sure that two typed password equals to each other.

So here we adding it:

public class RegTryViewModel : RegTry
{
    [Required]
    [EqualTo("Password", ErrorMessage = "You should type two identical passwords to continue")]
    public string ConfirmPassword { get; set; }
}

View is strongly typed view with RegTryViewModel model.

I just ask here to make sure I’m doing everything right. The thing that makes me feel uncomfortable is that I spread validation logic between IRegTry interface and the RegTryViewModel class. But I can’t add ConfirmPassword property to IRegTry interface because base SQL to LINQ class doesn’t has it at all.
Thanks in advance guys!

  • 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-27T03:16:38+00:00Added an answer on May 27, 2026 at 3:16 am

    I know that you already accepted an answer for this but I think it may be better to set this up using partial classes. As long as you set up the partial class in the same namespace with the same name, everything will get set up automatically. Here is an example of how I set this up in one of my projects:

    namespace OperationsMetrics
    {
    [MetadataType(typeof(ClientStatMD))]
    public partial class client_wkly_stat : IValidatableObject
    {
        public class ClientStatMD
        {
            [Required(ErrorMessage = "Client selection is required")]
            public virtual int client_id { get; set; }
            [Required(ErrorMessage = "SLAs met is required")]
            public virtual int wkly_sla_met { get; set; }
            [Required(ErrorMessage = "Total SLAs possible is required")]
            public virtual int wkly_sla_req { get; set; }
            [Required(ErrorMessage = "Number of input files is received")]
            public virtual int num_inp_files_rec { get; set; }
            [Required]
            public string client_name { get; set; } 
    
        }
    
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (wkly_sla_met > wkly_sla_req)
            {
                yield return new ValidationResult("SLAs met cannot be greater that SLAs possible");
            }
    
    
        }
        public string client_name { get; set; } //this isn't a part of the actual db object but can still be accessed in the Validate method
    }
    

    }

    You can set up the Partial Class as an IValidatableObject which implements its own Validate method. You can have a check for Confirm==Password in your Validate method.

    You can get some more information in this Pluralsight Video

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

Sidebar

Related Questions

I have picked up a quick PHP project that I need the use of
I have been slowly learning SQL the last few weeks. I've picked up all
I'm investigating the use of Entity Framework in an upcoming project, but I have
I have an ASP.NET website that I built that has grown considerably in size
I need to have Where Linq functionality in my own code. Let me explain:
I have picked up this code(DragandDrop.jsp) from this page :: http://jsfiddle.net/petersendidit/S4QgX/ I am getting
I am working on an ASP.NET WebForms application, and I have been asked to
The first language I learnt was PHP, but I have more recently picked up
I have a rails app that has picked up a bit of traction, but
I have picked a basic example of printing Hello World on screen when the

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.