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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:36:20+00:00 2026-05-22T22:36:20+00:00

I used LINQ to SQL to generate a dbml file which contains the database

  • 0

I used LINQ to SQL to generate a dbml file which contains the database model for my database table. I want to use UIHint to let MVC present some fields as DropDownLists or Checkboxes in edit mode. But if I change the file, it will be lost if it’s been regenerated. How should I solve that issue? I’m quite new to MVC and still learning. I’ve set up a controller with views for all CRUD elements, but now I’m finetuning and I’m running into this problem.

  • 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-22T22:36:21+00:00Added an answer on May 22, 2026 at 10:36 pm

    Since Linq-to-SQL auto-generates partial classes, you’ll need to create a partial ‘buddy class’ where you will add your Data Annotations. Your buddy class mirrors portions of the auto-generated class that you need to modify. You tie them together with [MetadataType(typeof(BuddyClassName))] The partial buddy class and the auto-generated partial class will be merged together when you compile your project.

    In an example given that:

    • Your namespace is “Project.Models”
    • Your Linq-To-Sql class is called “Products”

      using System.ComponentModel.DataAnnotations;
      
      namespace Project.Models
      {
        [MetadataType(typeof(ProductsMeta))]
        public partial class Products
        {
          // You can extend the products class here if desired.
      
          public class ProductsMeta
          {
            // This is a Linq-to-Sql Buddy Class      
            // In here you can add DataAnnotations to the auto-generated partial class
      
            [Key]
            public int ProductKey { get; set; }
      
            [Display (Name = "Product Name")]
            [Required(ErrorMessage = "Product Name Required")]
            [StringLength(255, ErrorMessage = "Must be under 255 characters")]
            public string ProductName { get; set; }
      
            [UIHint("MultilineText")]
            public string Description { get; set; }
          }
        }
      }
      

    These articles were very helpful:

    1. ScottGu: ASP.NET MVC 2: Model Validation
    2. How to: Validate Model Data Using DataAnnotations Attributes
    3. Validating with Data Annotation Validators
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say if I used the Linq to Sql concept to interact with database
Can SQL Server 2000 be used as the database for LINQ to SQL? Does
I have used LINQ to SQL with a update stored procedure to update databases
I used the LINQ to SQL designer in Visual Studio to create an object
I've been programming for a while and have used LINQ-To-SQL and LINQ-To-Entities before (although
I've created a business layer with a database model to be used in an
I have not hardly touched EF4, but I've used Linq to sql quite a
I have looked here : LINQ To SQL exception: Local sequence cannot be used
I have an SQL query (generated by LINQ to Entities) which is roughly like
I used linq to sql many times its work correctly but today something wrong

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.