Linq + DateTime weirdness
-
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)
-
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)
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.
-
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.
Thanx Gideon. that helped
Harvey Saayman - South Africa Junior Developer .Net, C#, SQL
you.suck = (you.passion != Programming)