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

The Archive Base Latest Questions

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

I’m getting the following error in my MVC2 app using Linq to SQL (I

  • 0

I’m getting the following error in my MVC2 app using Linq to SQL (I am new to both). I am connected to an actual SQL server not weird mdf:

System.InvalidOperationException The null value cannot be assigned to a member with type System.Int64 which is a non-nullable value type

My SQL table has a column called MessageID. It is BigInt type and has a primary key, NOT NULL and an IDENTITY 1 1, no Default

In my dbml designer it has the following declaration for this field:

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_MessageId", AutoSync=AutoSync.OnInsert, DbType="BigInt NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
public long MessageId
{
    get
    {
        return this._MessageId;
    }
    set
    {
        if ((this._MessageId != value))
        {
            this.OnMessageIdChanging(value);
            this.SendPropertyChanging();
            this._MessageId = value;
            this.SendPropertyChanged("MessageId");
            this.OnMessageIdChanged();
        }
    }
}

It keeps telling me that null cannot be assigned – I’m not passing through null! It’s a long – it can’t even be null!

Am I doing something stupid? I can’t find a solution anywhere!

I made this work by changing the type of this property to Nullable<long> but surely this can’t be right?

Update:
I am using InsertOnSubmit. Simplified code:

public ActionResult Create(Message message)
{
    if (ModelState.IsValid)
    {
       var db = new MessagingDataContext();
       db.Messages.InsertOnSubmit(message);
       db.SubmitChanges(); //line 93 (where it breaks)
    }
}

breaks on SubmitChanges() with the error at the top of this question.

Update2:
Stack trace:

   at Read_Object(ObjectMaterializer`1 )
   at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicInsert(TrackedObject item)
   at System.Data.Linq.ChangeDirector.StandardChangeDirector.Insert(TrackedObject item)
   at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
   at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
   at Qanda.Controllers.MessagingController.Ask(Message message) in C:\Qanda\Qanda\Controllers\MessagingController.cs:line 93

Update3:
No one knows and I don’t have enough clout to offer a bounty! So continued on my ASP.NET blog. Please help!

  • 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:20+00:00Added an answer on May 15, 2026 at 8:11 am

    It has taken a while but I have discovered this was happening and thought I’d share. It was because the table had a trigger on insert. I’ve wrote about it in more detail here optimistic concurrency exception with triggers. Although this is with entity framework, I’m still sure it is the trigger causing my dismay from the start

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

Sidebar

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.