Null values with mySQL
Posted: Fri 06 Mar 2009 16:19
I am using LINQ with MySQL and am having problems null values.
I have two tables; "Issue" and "Fix". There is a foreign key in the "Issue" table such that "Issue.FixID" references "Fix.ID". Cascade delete and update are on for this relationship.
One "Fix.ID" can statisfy multiple "Issues". But an "Issue" may have no "Fix" in which case its "FixID" is null on the database.
I have used your Enity Developer to produce the entity classes. The code it generated for the FixID property is:
_
Public Property FixID() As System.Int32
Get
Return Me._FixID
End Get
Set
If ((Me._FixID = value) _
= false) Then
If Me._aqtweb_fix.HasLoadedOrAssignedValue Then
Throw New System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException
End If
Me.OnFixIDChanging(value)
Me.SendPropertyChanging
Me._FixID = value
Me.SendPropertyChanged("FixID")
Me.OnFixIDChanged
End If
End Set
End Property
When I look at "Issue.FixID" for an "Issue" with this values a "Null", the property returns zero. But specifying zero for an update or insert does not (obviously) return null to the database - it tries to insert zero which causes the operation to fail as there is no "Fix.ID" with a value of zero.
Please can you tell me how to specify a null database value via LINQ when I update an existing "Issue" (i.e. how to set "Issue.FixID" = null) and when I insert a new "Issue" with its "Issue.FixID" = null?
I am using:
Entity developer standard V1.0.50
dbForge Fusion for MySQL standard 3.0.183
dotConnect for mySQL V5.0.12
Thanks
I have two tables; "Issue" and "Fix". There is a foreign key in the "Issue" table such that "Issue.FixID" references "Fix.ID". Cascade delete and update are on for this relationship.
One "Fix.ID" can statisfy multiple "Issues". But an "Issue" may have no "Fix" in which case its "FixID" is null on the database.
I have used your Enity Developer to produce the entity classes. The code it generated for the FixID property is:
_
Public Property FixID() As System.Int32
Get
Return Me._FixID
End Get
Set
If ((Me._FixID = value) _
= false) Then
If Me._aqtweb_fix.HasLoadedOrAssignedValue Then
Throw New System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException
End If
Me.OnFixIDChanging(value)
Me.SendPropertyChanging
Me._FixID = value
Me.SendPropertyChanged("FixID")
Me.OnFixIDChanged
End If
End Set
End Property
When I look at "Issue.FixID" for an "Issue" with this values a "Null", the property returns zero. But specifying zero for an update or insert does not (obviously) return null to the database - it tries to insert zero which causes the operation to fail as there is no "Fix.ID" with a value of zero.
Please can you tell me how to specify a null database value via LINQ when I update an existing "Issue" (i.e. how to set "Issue.FixID" = null) and when I insert a new "Issue" with its "Issue.FixID" = null?
I am using:
Entity developer standard V1.0.50
dbForge Fusion for MySQL standard 3.0.183
dotConnect for mySQL V5.0.12
Thanks