Detects null values, and does not appear inconsistent with mapping types

Source: Internet
Author: User

   /// <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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.