is it possible that you have a null value in the DB? (so it can't get casted to dateTime?) if so - either fix the DB (add NOT NULL constraint and fix the data) or use a nullable datetime for the property
On Sat, Mar 7, 2009 at 5:07 PM, dacanetdev <[email protected]>wrote: > > I'm getting this error, could you please help me with this? > > The problem is with the property FechaCreacion that it's a DateTime. I > tried with Timestamp and also as string, still getting the error. > > Thanks for your help > > This is the error > > NHibernate.PropertyAccessException: Invalid Cast (check your mapping > for property type mismatches); setter of > JCES.ControlObra.Entities.Obra ---> System.InvalidCastException: > Specified cast is not valid. > at (Object , Object[] , SetterCallback ) > at NHibernate.Bytecode.Lightweight.AccessOptimizer.SetPropertyValues > (Object target, Object[] values) > at > NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValuesWithOptimizer > (Object entity, Object[] values) > > > This is de Mapping file > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" > assembly="JCES.ControlObra.Entities" > namespace="JCES.ControlObra.Entities"> > <class > name="JCES.ControlObra.Entities.Obra,JCES.ControlObra.Entities" > table="Obra"> > <id name="ObraId" column="ObraId" type="Int32" > unsaved-value="0"> > <generator class="native" /> > </id> > <property name="NumObra" column="NumObra" type="string" > length="50" > not-null="true" unique="true" /> > <property name="NombreObra" column="NombreObra" > type="string" > length="400" not-null="true" /> > <property name="FechaCreacion" column="FechaCreacion" > type="DateTime" not-null="true" /> > <property name="CostoEstatal" column="CostoEstatal" > type="Decimal" > not-null="false" /> > <property name="CostoFederal" column="CostoFederal" > type="Decimal" > not-null="false" /> > <property name="CostoOtros" column="CostoOtros" > type="Decimal" not- > null="false" /> > > <many-to-one name="Municipio" class="Municipio" > column="MunicipioId" /> > <many-to-one name="Localidad" class="Localidad" > column="LocalidadId" /> > <many-to-one name="TipoObra" class="TipoObra" > column="TipoObraId" / > > > </class> > </hibernate-mapping> > > This is the class > > public class Obra > { > > private int obraId; > private string numObra; > private string nombreObra; > private TipoObra tipoObra; > private DateTime fechaCreacion; > private Localidad localidad; > private Municipio municipio; > private double costoEstatal; > private double costoFederal; > private double costoOtros; > > public Obra() > { > > } > > public virtual int ObraId > { > get > { > return obraId; > } > set > { > obraId = value; > } > } > > public virtual string NumObra > { > get > { > return numObra; > } > set > { > numObra = value; > } > } > > public virtual string NombreObra > { > get > { > return nombreObra; > } > set > { > nombreObra = value; > } > } > > public virtual TipoObra TipoObra > { > get > { > return tipoObra; > } > set > { > tipoObra = value; > } > } > > public virtual Municipio Municipio > { > get > { > return municipio; > } > set > { > municipio = value; > } > } > > public virtual Localidad Localidad > { > get > { > return localidad; > } > set > { > localidad = value; > } > } > > public virtual DateTime FechaCreacion > { > get > { > return fechaCreacion; > } > set > { > fechaCreacion = value; > } > } > > public virtual double CostoEstatal > { > get > { > return costoEstatal; > } > set > { > costoEstatal = value; > } > } > > public virtual double CostoFederal > { > get > { > return costoFederal; > } > set > { > costoFederal = value; > } > } > > public virtual double CostoOtros > { > get > { > return costoOtros; > } > set > { > costoOtros = value; > } > } > > }//end Obra > > > > -- Ken Egozi. http://www.kenegozi.com/blog http://www.delver.com http://www.musicglue.com http://www.castleproject.org http://www.gotfriends.co.il --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
