/// <summary> ///detects null values, and does not appear inconsistent with mapping types/// </summary> /// <typeparam name= "T" ></typeparam> /// <param name= "NULLSB1" ></param> /// <param name= "ERRORSB" ></param> Public Static voidCheckhibernatemappingtype<t> ( outStringBuilder NULLSB1, outStringBuilder ERRORSB)whereT:framework.domain.entity,New() {NULLSB1=NewStringBuilder (); ERRORSB=NewStringBuilder (); varCTX =Spring.Context.Support.ContextRegistry.GetContext (); varDao =Getdao (); varmapping = ((Spring.Data.NHibernate.LocalSessionFactoryObject) ctx. GetObject ("&sessionfactory")). Configuration.getclassmapping (typeof(T)); varPmap =mapping. Propertyiterator; varTableName1 =mapping. Table.name; varTable = Dao.executedataset (NewQueryInfo () {customsql ="SELECT * from"+ tableName1}). tables[0]; Hashtable Columnstype=NewHashtable (); foreach(DataColumn Colinchtable. Columns) {Columnstype.add (col. ColumnName, Col. Datatype.name); } stringPrimaryKey =( (NHibernate.Mapping.Column) (Mapping. Key.ColumnIterator.FirstOrDefault ())). Name; StringBuilder SB=NewStringBuilder (); StringBuilder SB1=NewStringBuilder (); foreach(DataRow Drinchtable. Rows) {foreach(varIteminchPmap) {NHibernate.Mapping.Column C=(NHibernate.Mapping.Column) item. Columniterator.firstordefault (); //1-to-many attributes, such as children, do not have corresponding columns if(c! =NULL) { stringColumntypename =Columnstype[c.name]. ToString (); Try { if(Dr[c.name] isDBNull) {nullsb1. Append ("PRIMARY Key"+ Dr[primarykey]. ToString () +"column"+ C.name +"The contract type is:"+ Columntypename +"value is: null\r\n"); Continue; } Switch(columntypename) { Case "String": Break; Case "Int16": Convert.ToInt16 (Dr[c.name]); Break; Case "Int32": Convert.ToInt32 (Dr[c.name]); Break; Case "Int64": Convert.toint64 (Dr[c.name]); Break; Case "Decimal": Convert.todecimal (Dr[c.name]); Break; Case "DateTime": Convert.todatetime (Dr[c.name]); Break; Case "Boolean": Case "BOOL": Convert.toboolean (Dr[c.name]); Break; default: Break; } } Catch(Exception ex) {sb. Append ("PRIMARY Key"+ Dr[primarykey]. ToString () +"column"+ C.name +"The contract type is:"+ Columntypename +"values are:"+ Dr[c.name] +"?? Type conversion exception \ r \ n"); } } } } }
Detect null values, and whether there is a problem with mapping type inconsistency