Are there any admins that can chime in on this?
I'm running into another issue where an artificial property with a converter on it is causing issues in concurrency.
A nullable datetime column is mapped to an artificial nullable datetime property with a converter that is supposed to convert nulls and dates before 1899 in the database to nulls in the application.
I think this is causing an issue where when I try to update an artificial datetime property, the optimistic concurrency verification is attempting to find the row by using 'null', when in the database it's '1899-1-1'. So the row is not found, exception is thrown.
Some code to aid in troubleshooting.
mappingConfiguration.HasArtificialPrimitiveProperty(udf.FieldName,
typeof
(Nullable<DateTime>)).HasFieldName(fieldName).ToColumn(udf.FieldName).WithConverter<DateTimeConverter>();
public
class
DateTimeConverter : AdoTypeConverter
{
public
override
Type DefaultType
{
get
{
return
typeof
(DateTime?); }
}
public
override
object
Read(
ref
DataHolder holder)
{
//check if the value is dbnull
bool
isNull = holder.Reader.IsDBNull(holder.Position);
//set wheather or not there is a value
holder.NoValue = isNull;
//if the value is null, then we need to return default values
DateTime? value =
null
;
if
(!isNull)
{
//the value is not null, so here we want to pull the value out, and convert it
value = holder.Reader.GetValue(holder.Position)
as
DateTime?;
//if the value is nullabel, or needs to be boxed, we set the ObjectValue Property of the DataHolder
if
(value.RemoveTime() <= InteumDate.EMPTY_DATE)
value =
null
;
}
holder.ObjectValue = value;
//now we return our value
return
value;
}
public
override
void
Write(
ref
DataHolder holder)
{
//set the db type
holder.Parameter.DbType = System.Data.DbType.DateTime;
//if there is no value we could specify what to set the db field to
if
(holder.NoValue)
{
holder.Parameter.Value = InteumDate.EMPTY_DATE;
}
else
{
holder.Parameter.Value = holder.ObjectValue ==
null
? InteumDate.EMPTY_DATE : holder.ObjectValue
as
DateTime?;
}
}
public
override
bool
CreateLiteralSql(
ref
DataHolder holder)
{
//If there is no value, then we just want to query against null.
if
(holder.NoValue)
{
holder.StringValue =
"NULL"
;
//returning false indicates that no quotes are required. We want NULL instead of 'NULL'
return
false
;
}
else
{
holder.DateTimeValue = (holder.ObjectValue
as
DateTime?).GetValueOrDefault(InteumDate.EMPTY_DATE);
// return true indicates that quotes are needed around the value
return
true
;
}
}
}
Exception message:
"Row not found: GenericOID@50ac1abb TECHNOL PRIMARYKEY=4210
UPDATE [TECHNOL] SET [RUPDATEDD] = ?, [UDFG6EDDT] = ? WHERE [PRIMARYKEY] = ? AND [RUPDATEDD] = ? AND [UDFG6EDDT] is null"
The value for column UDFG6EDDT in the database is (SQL Server) '1899-1-1'. So natually, there is no row found with the given filter. How is this fixed?