Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Linq + DateTime weirdness

Linq + DateTime weirdness

Scheduled Pinned Locked Moved LINQ
csharpquestiondatabaselinq
3 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Harvey Saayman
    wrote on last edited by
    #1

    Hey guys while working with a DateTime in my Linq query i noticed that one of my Linq generated variable's data type says "DateTime?" in the intellisence. Furthermore i realized that i cant get to the DateTime's properies like TimeOfDay... Which i need. Then i had a look at the generated code and found this...

    The messed up one

    [Column(Storage="_SHF_Break1Start_DT", DbType="DateTime")]
    public System.Nullable SHF_Break1Start_DT
    {
    get
    {
    return this._SHF_Break1Start_DT;
    }
    set
    {
    if ((this._SHF_Break1Start_DT != value))
    {
    this.OnSHF_Break1Start_DTChanging(value);
    this.SendPropertyChanging();
    this._SHF_Break1Start_DT = value;
    this.SendPropertyChanged("SHF_Break1Start_DT");
    this.OnSHF_Break1Start_DTChanged();
    }
    }
    }

    The Correct One

    [Column(Storage="_SHF_PostStopInterval3Start_DT", DbType="DateTime NOT NULL")]
    public System.DateTime SHF_PostStopInterval3Start_DT
    {
    get
    {
    return this._SHF_PostStopInterval3Start_DT;
    }
    set
    {
    if ((this._SHF_PostStopInterval3Start_DT != value))
    {
    this.OnSHF_PostStopInterval3Start_DTChanging(value);
    this.SendPropertyChanging();
    this._SHF_PostStopInterval3Start_DT = value;
    this.SendPropertyChanged("SHF_PostStopInterval3Start_DT");
    this.OnSHF_PostStopInterval3Start_DTChanged();
    }
    }
    }

    why does this happen? and how can i now get the TimeOfDay for that variable? thanx

    Harvey Saayman - South Africa Junior Developer .Net, C#, SQL

    you.suck = (you.passion != Programming)

    G 1 Reply Last reply
    0
    • H Harvey Saayman

      Hey guys while working with a DateTime in my Linq query i noticed that one of my Linq generated variable's data type says "DateTime?" in the intellisence. Furthermore i realized that i cant get to the DateTime's properies like TimeOfDay... Which i need. Then i had a look at the generated code and found this...

      The messed up one

      [Column(Storage="_SHF_Break1Start_DT", DbType="DateTime")]
      public System.Nullable SHF_Break1Start_DT
      {
      get
      {
      return this._SHF_Break1Start_DT;
      }
      set
      {
      if ((this._SHF_Break1Start_DT != value))
      {
      this.OnSHF_Break1Start_DTChanging(value);
      this.SendPropertyChanging();
      this._SHF_Break1Start_DT = value;
      this.SendPropertyChanged("SHF_Break1Start_DT");
      this.OnSHF_Break1Start_DTChanged();
      }
      }
      }

      The Correct One

      [Column(Storage="_SHF_PostStopInterval3Start_DT", DbType="DateTime NOT NULL")]
      public System.DateTime SHF_PostStopInterval3Start_DT
      {
      get
      {
      return this._SHF_PostStopInterval3Start_DT;
      }
      set
      {
      if ((this._SHF_PostStopInterval3Start_DT != value))
      {
      this.OnSHF_PostStopInterval3Start_DTChanging(value);
      this.SendPropertyChanging();
      this._SHF_PostStopInterval3Start_DT = value;
      this.SendPropertyChanged("SHF_PostStopInterval3Start_DT");
      this.OnSHF_PostStopInterval3Start_DTChanged();
      }
      }
      }

      why does this happen? and how can i now get the TimeOfDay for that variable? thanx

      Harvey Saayman - South Africa Junior Developer .Net, C#, SQL

      you.suck = (you.passion != Programming)

      G Offline
      G Offline
      Gideon Engelberth
      wrote on last edited by
      #2

      As for why, the difference is right here: [Column(Storage="_SHF_Break1Start_DT", DbType="DateTime")] public System.Nullable SHF_Break1Start_DT [Column(Storage="_SHF_PostStopInterval3Start_DT", DbType="DateTime NOT NULL")] public System.DateTime SHF_PostStopInterval3Start_DT In the first case, you database column is defined to allow null. In the second, null is not allowed. To get the value from the nullable field, you should be able to use the value property.

      H 1 Reply Last reply
      0
      • G Gideon Engelberth

        As for why, the difference is right here: [Column(Storage="_SHF_Break1Start_DT", DbType="DateTime")] public System.Nullable SHF_Break1Start_DT [Column(Storage="_SHF_PostStopInterval3Start_DT", DbType="DateTime NOT NULL")] public System.DateTime SHF_PostStopInterval3Start_DT In the first case, you database column is defined to allow null. In the second, null is not allowed. To get the value from the nullable field, you should be able to use the value property.

        H Offline
        H Offline
        Harvey Saayman
        wrote on last edited by
        #3

        Thanx Gideon. that helped

        Harvey Saayman - South Africa Junior Developer .Net, C#, SQL

        you.suck = (you.passion != Programming)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups