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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:11:47+00:00 2026-05-15T08:11:47+00:00

I am using LINQ to SQL with single table inheritance for an audit log.

  • 0

I am using LINQ to SQL with single table inheritance for an audit log. There is a field/property called Type that i am using as the dicriminator and i have created a base type and a single inherited type (there will be more later if i can actually get this to work).

So that i don’t have to write a different method to insert each different derived audit type the method takes the base type, but it doesn’t work, it throws a SQLTypeException saying that the date is out of range, despite the fact that the only date field has been set using DateTime.Now. I have written some basic debugging code and found a strange effect. The below code works fine:

tOnHoldReasonAudit dbAudit = new tOnHoldReasonAudit();
dbAudit.ApplicationID = 1;
dbAudit.Date = DateTime.Now;
dbAudit.UserID = 9;
pi_DataContext.tApplicationAudits.InsertOnSubmit(dbAudit);
pi_DataContext.SubmitChanges();

However if i change the first line to

tApplicationAudit dbAudit = new tOnHoldReasonAudit();

where tApplicationAudit is the base type it throws the exception, specifically:

System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Why does this not work, what exactly is going on here. In my live code i have a method AddAudit(tApplicationAudit Audit) that does the actual work, i don’t want to have to write an add method for each different derived type as this defeats the whole object, if i have to do that i might as well do away with the derived audit types and just set the type property on the base class.

Update:

Below is the initial part of the class definitions for the LinqTSql audit types that was created by O/R designer:

[Table(Name="dbo.tApplicationAudit")]
[InheritanceMapping(Code="1", Type=typeof(tOnHoldReasonAudit), IsDefault=true)]
public partial class tApplicationAudit : INotifyPropertyChanging,INotifyPropertyChanged

public partial class tOnHoldReasonAudit : tApplicationAudit
  • 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-15T08:11:48+00:00Added an answer on May 15, 2026 at 8:11 am

    I figured this out. It was because the properties on the derived type were simply hiding the coresponding properties on the base type. When i changed the properties on the base type to virtual and the override on the derived type, it fixed it. I think linq to sql must have been casting it back to the derived type to access the data.

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

Sidebar

Related Questions

We are using Linq To SQL with our own data context logic that executes
We are using Linq To SQL with our own data context logic that executes
I have been using LINQ to SQL for a while, and there is one
Using LINQ to SQL, I have an Order class with a collection of OrderDetails.
Using LINQ to SQL db.Products.Where(c => c.ID == 1).Skip(1).Take(1).ToList(); executes SELECT [t1].[ID], [t1].[CategoryID], [t1].[Name],
When using Linq to SQL and stored procedures, the class generated to describe the
I'm using LINQ to SQL classes in a project where the database design is
I've been using Linq to SQL for some time now and I find it
I'm using LINQ to SQL and C#. I have two LINQ classes: User and
I have started using Linq to SQL in a (bit DDD like) system which

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.