[dblinq] DbMetal generated entity on column with type System.Nullable(Of Date) not working

14 views
Skip to first unread message

wind cloud

unread,
Apr 28, 2010, 10:49:43 PM4/28/10
to DbLinq
Hello, I am using dblinq on mysql. I used the dbmetal to generate the
entities datacontext class in VB. Things all seems fine but except
with columns of DateTime with null value allowed. DbMetal generate
System.Nullable(Of Date) as the column properties of course, like the
following

<Column(Storage:="_birthDate", Name:="Birth Date", DbType:="datetime",
AutoSync:=AutoSync.Never), _
DebuggerNonUserCode()> _
Public Property BirthDate() As System.Nullable(Of Date)
Get
Return Me._birthDate
End Get
Set
If _birthDate <> Value Then
Me.OnBirthDateChanging(Value)
Me.SendPropertyChanging()
Me._birthDate = Value
Me.SendPropertyChanged("BirthDate")
Me.OnBirthDateChanged()
End If
End Set
End Property

Doesn't look like any problem upon first look. However, when I put my
application to test, I found out all my birthdate columns alike
doesn't get updated/inserted into the mysql database. Checked the
bindings, can't seem to find anything wrong. And when I started
debugging my program by stepping into the little piece of code above,
and bang, the "if _birthDate <> Value then" always evaluate to a false
regardless of the Value being "Nothing" or a valid date.

I don't have much experience playing with nullable types in VB, so I
checked around the internet. The problem can be fixed by replacing it
with "if Nullable.Compare(_birthDate, Value) <> 0 then", then things
start to work ok. I am not sure if it affects Nullable of integer,
string, or other types as well, but nullable of date seems just not
working for me using the default code from DbMetal.

I am not really sure if my fix is a fix or I misuse Nullable type,
just want to check with you guys to see if it's really a problem and
hope the Dblinq coders could fix it in the future. Thanks.

--
You received this message because you are subscribed to the Google Groups "DbLinq" group.
To post to this group, send email to dbl...@googlegroups.com.
To unsubscribe from this group, send email to dblinq+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dblinq?hl=en.

Jonathan Pryor

unread,
Apr 28, 2010, 11:08:39 PM4/28/10
to dbl...@googlegroups.com
On Wed, 2010-04-28 at 19:49 -0700, wind cloud wrote:
> Hello, I am using dblinq on mysql. I used the dbmetal to generate the
> entities datacontext class in VB. Things all seems fine but except
> with columns of DateTime with null value allowed. DbMetal generate
> System.Nullable(Of Date) as the column properties of course, like the
> following

Thank you for the report. I've added this as a bug:

http://code.google.com/p/dblinq2007/issues/detail?id=249

> I am not really sure if my fix is a fix or I misuse Nullable type,
> just want to check with you guys to see if it's really a problem and
> hope the Dblinq coders could fix it in the future. Thanks.

Your fix looks sane. It's a bug in the DbMetal generator (the perils of
not actually testing the VB output, other than to ensure that it
actually compiles, while only testing the C# output...).

Thanks,
- Jon
Reply all
Reply to author
Forward
0 new messages