Page 1 of 1

Number(1) to Boolean conversion

Posted: Wed 31 Mar 2010 16:30
by ChrisWalker
I have an oracle table that has a column 'ORDINAL' defined as a Number(1). In my code I need to modify the value and save it back to the database. I don't control the database. It is a legacy database being generated by a different entity.

I opened up the Entity Developer for dotConnect modeling tool and added the USER_PASSWORD_HISTORY table. The column ORDINAL gets added as a type of Boolean. If I try to edit the type to 'Int32' (or byte or anything else) I get the error below.

I was thinking about going into the ...Designer.cs file and manually changing bool to int but I have been regenerating the model as I add and modify tables and don't want to have to do that every time I modify the model. Any help?


1 Member Mapping specified is not valid. The type 'Edm.Int32[Nullable=False,DefaultValue=]' of member 'Ordinal' in type 'DMS.Entities.Pearl.User.UserPasswordHistory' is not compatible with 'Devart.Data.Oracle.bool[Nullable=False,DefaultValue=]' of member 'ORDINAL' in type 'DMS.Entities.Pearl.User.Store.USER_PASSWORD_HISTORY'. UserPasswordHistory

Posted: Thu 01 Apr 2010 07:55
by AndreyR
The problem is associated with the fact that the store type of the column is set to bool while you are setting the conceptual type to Int32. Change the store type in the Store part of the model to the corresponding one (int, for example).

Posted: Mon 05 Apr 2010 14:54
by ChrisWalker
If I understand what you are saying it is to change the bolded bool to int in the part of the model shown below. However, if I do that, then I will need to do it EVERYTIME I regenerate the model correct?

///
/// There are no comments for Property Ordinal in the schema.
///
[global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(IsNullable=false)]
[global::System.Runtime.Serialization.DataMemberAttribute()]
public bool Ordinal
{
get
{
bool value = this._Ordinal;
OnGetOrdinal(ref value);
return value;
}
set
{
this.OnOrdinalChanging(ref value);
this.ReportPropertyChanging("Ordinal");
this._Ordinal = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value);
this.ReportPropertyChanged("Ordinal");
this.OnOrdinalChanged();
}
}
private bool _Ordinal;
partial void OnGetOrdinal(ref bool value);
partial void OnOrdinalChanging(ref bool value);
partial void OnOrdinalChanged();

Posted: Tue 06 Apr 2010 14:25
by AndreyR
Not quite, there is no need to make any changes in the generated code.
You should open your .edmx model (if you are using Microsoft designer) using XML Editor you like and change the type of the property to bool in both SSDL and CSDL part of the model.
In case you are using Entity Developer it will be enough only to set the corresponding properties in design time (both in the Model and Store parts).
The code will be regenerated correctly, but any update made to the model by using Update from database wizard will overwrite the manual changes made to the model - this is a limitation of Microsoft designer. I recommend you to use Entity Developer.

Posted: Tue 06 Apr 2010 17:50
by ChrisWalker
Excellent. I was able to modify both the store and conceptual entries in the .edmx file and then bring up the designer again and regenerate the code correctly. Thanks for the help