I am trying to set a value for Model
property, by checking firs the COM
type and then the outgoing Model
type in the IF ELSE
statement. However, I am only able to achieve this for property GroupID
and not for ParentID
.
SQL Database:
GroupID tinyint
ParentID smallint (nullable)
Model:
public Int16? GroupID { get; set; }
public Int16? ParentID { get; set; }
Using reflection, I am trying to set default model value depending on the Data Type of the property.
C#:
if (comModel.FieldValue(prop.Name).GetType() == typeof(short))
{
//checking out going model type and setting value
if (modelOut.GetType().GetProperty(prop.Name).PropertyType == typeof(bool))
{
modelOut.GetType().GetProperty(prop.Name).SetValue(modelOut, false);
}
else
{
modelOut.GetType().GetProperty(prop.Name).SetValue(modelOut, (short)-999);
}
}
// I have also tried this but does not fall into here
else if (comModel.FieldValue(prop.Name).GetType() == typeof(Int16?))
{
var s = true;
}
After investigating, I am assuming the SQL
data types are different and this may be a reason why. If so, then the Int?16
should have captured it but it doesn't.
Any help is appreciated. Thanks
Aucun commentaire:
Enregistrer un commentaire