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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:05:48+00:00 2026-06-17T09:05:48+00:00

In my database there are 5 fields at the end of each table: State

  • 0

In my database there are 5 fields at the end of each table:

  • State
  • CreatedDate
  • CreatedBy
  • ModifiedDate
  • ModifiedBy

I am using the entity framework to generate the POCO objects for the database.
I have Dal layer to handle all of the CRUD operations.

It’s a pain to constantly copy and paste the same code to fill in the 5 fields.
I am wondering if anyone has a generic method that can handle any entity object and fill the fields in for me.

  • 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-17T09:05:48+00:00Added an answer on June 17, 2026 at 9:05 am

    You should implement a common base class that has these properties, and derive your POCO classes from that base class.

    You can automatically handle setting things like the Create/ModifiedDate and User by overriding SaveChanges() in your context class. That frees the object consumers from the need to set those properties everywhere the classes are consumed.

    Here’s an example of that sort of code from one of my projects (in my case, objects that have a LastModified property implement an interface IHasLastModified):

        public override int SaveChanges()
        {
            DateTime now = DateTime.UtcNow;
            foreach (ObjectStateEntry entry in (this as IObjectContextAdapter).ObjectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified))
            {
                if (!entry.IsRelationship)
                {
                    IHasLastModified lastModified = entry.Entity as IHasLastModified;
                    if (lastModified != null)
                        lastModified.LastModified = now;
                }
            }
    
            int changes = base.SaveChanges();
            return changes;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there a standard or best practice with database table names and fields in
I have a Database named CarsType.accdb there are four fields in the data base
I have an ActiveRecord model whose fields mostly come from the database. There are
I'm setting all fields to nullable types where the back-end database fields they correspond
I am using PostgreSQL database. Having a table named metadatavalue with structure is as
I have a EMP table in my database with the following fields: id,name,post,joining_date. Whenever
I have a simple DB-table with few fields for articles database among that is
In my scheduling database, I have an assignments table with the following fields: |
Short Generating table with barcodes of items. Each item has exact quantity in database
In a database, there is a field that saves a closure date. This date

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.