find a location for property in a new city

Wednesday, 21 April 2010

LINQ to SQL - Null value cannot be assigned to a member with type System.Int64 which is a non-nullable value type

I am attempting an InsertOnSubmit and it is failing since "The null value cannot be assigned to a member with type System.Int64 which is a non-nullable value type" This LINQ to SQL is driving me crazy. Please help.

The table in the SQL database has a MessageID column which is a BigInt with primary key (NOT NULL IDENTITY 1 1) no Default.

The field looks like this in the designer file to the dbml:
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_MessageId", AutoSync=AutoSync.OnInsert, DbType="BigInt NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)] 
public long MessageId 
        return this._MessageId; 
        if ((this._MessageId != value)) 
            this._MessageId = value; 

So the problem is that null cannot be assigned... right. But I'm not passing null! How can I be? I'm using a long (a value type so can't be null by nature).

One workaround I found was making this field nullable but this feels like a hack since it should never be null. Anyway this just moves the problem to the ID not AutoSyncing OnInsert. (AutoSync=OnInsert is set).

Update and solution

Well it took me a while, I even posted on stackoverflow to no avail but finally worked out the problem and wrote about it in this post about optimistic concurrency exceptions on insert although by this time it has manifested itself in a new way since I'm using Entity Framework.

Follow britishdev on Twitter


  1. Great blog. Thank you! I put your feed on my RSS reader!
    Thesis Writing

  2. Are you looking for Cheap and best Essay Writing Service, stand out from our competition as the prime essay service provider.
    More to visit:

  3. Informative blog with good useful information.

  4. Very interesting posts, it is really informative to read these posts Keep posting.

    Affordable Essay Writing Services UK | UKEssayPapers

  5. Such an interesting blog. Thank you for sharing such post. visit my website to see my works.

  6. Such a nice blog and I appreciate your all efforts about your thoughts. it’s really good work. well done. I would like to share something really helpful for education.
    coursework writing service

  7. When I Install a sendy in my database, its show me lots of error sometime it crypt my database so some of tips it's helpful for me and its clear my concept.
    Online coursework help uk