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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:55:35+00:00 2026-06-13T10:55:35+00:00

I have an audit trailing system in my project from http://doddleaudit.codeplex.com/ . As you

  • 0

I have an audit trailing system in my project from http://doddleaudit.codeplex.com/.
As you can see on this image it records the EntityTable – which is the table name, and the EntityTableKey – which is the primary key enter image description here

I would like to associate the audit records with the tables it had recorder, then query the result in linq to sql. But the problem is if the audit table has record for orders and record for products it will never know just by the primary key, where does the record belong, thus i need to use the table name as part of the key.

So the question is: Is it possible to create a relation that will have a composite primary key that contains the table name in it?

AuditRecord to Orders
AuditRecord to Products
  • 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-13T10:55:36+00:00Added an answer on June 13, 2026 at 10:55 am

    You could do it, but I would recommend a bit different approach.

    Don’t use char/varchars/nvarchar in your PK/FK, it bloats the index. I would rather create another table that will hold TableId/TableName pairs of all your tables (you can use sys.tables.object_id for your id if you wish) and have a FK in AuditRecords to it. Then establish composite key between AuditRecords and AuditRecordFields (Id, TableId).

    Another thing:

    • EntityTable and AssociationTable should be of sysname type
    • AuditDate can be of type Date (available from SQL Server 2008)

    EDIT:

    If you like to access audit records from each object, you can create a base class for your audited objects and implement following method (beware, it’s untested):

    public IQueryable<AuditRecord> AuditRecords
    {
        get
        {
            MyContext ctx = new MyContext();
    
            var ars = from ar in ctx.AuditRecords
                      where ar.EntityTable.Equals(this.GetType().Name)
                      select ar;
    
            return ars;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an audio project I'm working on using BASS from Un4seen. This library
I have a table called 'Audit' in SQL Server 2005 like this: Name |
I have this problem where I have to audit a percent of my transtactions.
I have audit for records in a table. There multiple columns and each records
I have an audit Trail table where I store the records with time taken
Assume I have a controller method like this: [Audit] public JsonNetResult List(int start, int
I have a very large table (15 million rows, this is an audit table).
We have a trigger that creates audit records for a table and joins the
We have an Audit Message Handler and if any exceptions are thrown within this
We have audit columns set by triggers. For obscure security reasons predating my tenure

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.