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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:07:16+00:00 2026-06-17T06:07:16+00:00

I am new to MS’s MVC4, and I have been given a database for

  • 0

I am new to MS’s MVC4, and I have been given a database for which I must build a CRUD front-end. The tables all have composite primary keys of the form [TableID, TableName, EffectiveDate]. I cannot alter the database design. I used the Database-first technique and the EF 5.x DbContext generator for C# tool to create the models, but the generated model files do not contain annotations for the composite keys. Here is an example of the Department table, with primary key = [DeptID, DeptName, EffDate].

//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace BillableUnits4.Models
{
    using System;
    using System.Collections.Generic;

    public partial class Department
    {
        public int DeptID { get; set; }
        public string DeptName { get; set; }
        public System.DateTime EffDate { get; set; }
        public string Status { get; set; }
        public string Fund { get; set; }
        public string DeptNo { get; set; }
        public string RevenueAccount { get; set; }
        public string BalanceSheetAccount { get; set; }
    }
}

I’m betting the keys should look like this:

    [key] 
    public int DeptID { get; set; }
    [key]
    public string DeptName { get; set; }
    [key]
    public System.DateTime EffDate { get; set; }

Do I even need to annotate the primary key components? If so, should I add the annotations to the generated model files? (regenerating the files would erase any changes I make by hand, obviously). Is there a way to tell MVC4 / Visual Studio to generate the files with the proper annotations?

  • 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-06-17T06:07:17+00:00Added an answer on June 17, 2026 at 6:07 am

    You don’t have to annotate something that is obvious for the database 🙂 Your code will not use database specific annotations, so I wound’t worry about that.

    You might want to decorate your model with a [Required] or other annotations that make sense for your app’s data consistency. In such case you might either go with Partial Classes (http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx) or by implementing ViewModels (that you could modify without worrying about the auto-generated classes that you shouldn’t really modify)

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

Sidebar

Related Questions

(New to ASP.NET here.) I have a user control which should check for a
New to iPhone app development, I have a problem compiling (or Build and Run)
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
New to PHP and MySQL, have heard amazing things about this website from Leo
I have a jquery bug and I've been looking for hours now, I can't
New to pandas python. I have a dataframe (df) with two columns of cusips.
New to XMLHttpRequest, and here is some confusion for me: Why must we set
****New to C!**** I am running Dev-C++ 4.9.9.2 on Windows 7 (64 bit build)
(New to Objective-C, but well versed in C/C++). Presently I have an Objective-C class
New to Android and OpenCV. Been trying to to implement code from new book,

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.