SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)

    DateTime, Timestamps and SQL

    Ok, I have an issue where a table column needs to be either a datetime (preferred since it's a real sql server datatype) or a timestamp. The thing is, it might not actual have a value set. When I set the column to allow nulls, and there IS a null in a record, .NET complains that it can't convert null to int32 (this is in the autogenerated linq class code). The table definition changed after it was originaly imported, so do I need to regenerate the linq classes, or what? What's the best way to handle datetimes / timestamps here. Use datetime allowing nulls? Or int with default of 0 (timestamp)?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I haven't done LINQ in a long time, but I'm pretty sure if the column is marked as nullable, the code handles that correctly. You probably need to regenerate the classes.

    A timestamp of 0 is a specific date (January 1, 1970), I wouldn't try to treat that as null.

  3. #3
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Dropping the classes and regenerating did the trick. Thanks.

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,625
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Timestamp in SQL server is not a unix timestamp, but rather a special type of binary column pretty generally useless outside of SQL server.

    I'd run with DateTime as it is what you want, and as you've found nullable types can solve lots of DBNull issues . . .


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •