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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:33:26+00:00 2026-05-17T16:33:26+00:00

I am constanstly having problems with model design in MVC. Mostly all of my

  • 0

I am constanstly having problems with model design in MVC. Mostly all of my projects require some entities that are to be created, edited and deleted. Most of these entities have some common properties like creation date, modified date, author, modified by and in some cases even more descriptive properties are common. Because of that I have one single DB table to store them. For instance, Documents table and we store Invoices, Quotations and other business documents in it. I am using Entity Framework v4 for ORM, where we eventually end up with the Document entity.

How do I modify this entity or do I create a separate DocumentViewModel class for it to support multiple document types with common properties (so some form of inheritance or interface implementation should be implemented)? Besides identifying different document types I also need to have some types to have different Data Annotation rules (attributes).

For instance, Document table has PayDate column. Document type Invoice requires PayDate to be provided but document type Quotation does not.

This is the one single problem I am facing over and over with MVC and so far I’ve been handling it different every time but cannot decide how to properly handle it to achieve the maximum application maintainability and ease of development.

  • 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-17T16:33:26+00:00Added an answer on May 17, 2026 at 4:33 pm

    Have you considered making Documents entity abstract?

    From the DB side, you will have Documents table containing just the fields shared by all Invoices/Quoations/etc. This field will have an IDENTITY PK – e.g DocId.

    In the other tables, additional meta-data specific to that document can be stored, and the PK is a (non-IDENTITY) field DocId, which is also a FK to the Documents table.

    On the EF side, Documents becomes an abstract entity, and the other entities inherit from this entity. This allows a nice OO paradigm to exist, and makes your code more robust.

    We are currently using this scheme (EF4/SQL Server).

    Your scenario sounds very similar to ours – consider using Abstract Classes.

    EDIT

    Thought i’d add a bit more info to how i’ve actually implemented this scenario, to put you on the right track.

    As the comments to your Q state, we have little knowledge of your domain, therefore it’s hard to make informed opinions. Personally, i chose to make my entity abstract, because certain functionality required a “mixed-bag” of items to be returned in one hit. There are other ways to do this of course (such as a stored procedure), but this allows a nice fluent interface between my UI (which is MVC by the way) and my service layer.

    Works like this – here’s how i get a single Post:

    // var is strongly-typed to a "Post"
    var somePost = repository.FindSingle(10); 
    

    Here’s how i get a mixed-bag of Posts:

    // var is strongly-typed to a "ICollection<Post>".
    // "Title" is a property on my "Post" abstract POCO
    var mixedBagOfPosts = repository.FindAll<Post>(p => p.Title = "Some Title"); 
    

    Here’s how i get a collection of “Reviews” (child of Post):

    // var is strongly-typed to a "ICollection<Review>"
    // "Rating" is a property on my "Review" POCO (derived from Post)
    var reviews = repository.FindAll<Review>(r => r.Rating == 5.00);
    

    The kicker is my repository is implemented with generics, and the type parameter ensures type-safety:

    ICollection<T> FindAll<T>(Expression<Func<T,bool>> predicate) where T : Post
    

    And it’s implemented like this:

    return myContext.Posts.OfType<T>.Where(predicate).ToList();
    

    The OfType causes an inner join to the T (which is the child table), so only those records are returned.

    Of course, i also have a service layer mediating between my UI and repository, but this should get you on the right track.

    Also, you don’t have to go with the whole Expression-predicate thing, i like this because it minimizes the number of methods on my interface, and gives full querying power to my controllers, whilst ensuring the queries are deferred to the point of the service layer, but not further.

    If you don’t like this, you could of course have regular parameters (string title, etc).

    As i said, this architecture suited my domain requirements, so it may not necessarily suit yours, but hopefully it gives you some insight.

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

Sidebar

Related Questions

I have a script that constantly segfaults - the problem that I can't solve
I constantly hear how bad reflection is to use. While I generally avoid reflection
I am constantly learning new tools, even old fashioned ones, because I like to
I am constantly forgetting what the special little codes are for formatting .NET strings.
My coworker and I constantly argue about button sizes. I like to have buttons
I write financial applications where I constantly battle the decision to use a double
Lately I've found myself constantly running ILDASM to study the MSIL output of my
In Visual Studio.NET when coding I constantly use (no selection) CTRL-C, CTRL-V to make
While designing my site I am constantly faced with the issue of whether its
Before I upgraded to Firefox 3 I used to constantly use the View Source

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.