After the data from the database is queried by ADO, the DataReader is converted to object info.
Public classBaseinfo {/// <summary> ///Fill Entities/// </summary> /// <param name= "Dr" ></param> Public Virtual voidFill (DataRow dr) {propertyinfo[] PS= This. GetType (). GetProperties (); foreach(PropertyInfo pinfoinchPS) { if(Dr. Table.Columns.Contains (pinfo. Name) {pinfo. SetValue ( This, Dr[pinfo. Name],NULL); } } } /// <summary> ///Fill Entities/// </summary> /// <param name= "Dr" ></param> Public Virtual voidFill (DbDataReader dr) {propertyinfo[] PS= This. GetType (). GetProperties (); foreach(PropertyInfo pinfoinchPS) { intColindex =Dr. GetOrdinal (pinfo. Name); if(Colindex >=0&&!Dr. IsDBNull (Colindex)) {pinfo. SetValue ( This, Dr[pinfo. Name],NULL); } } } }
base class Baseinfo
Public classBeacondatainfo:baseinfo { Public stringseqno {Get;Set; } Public stringCBID {Get;Set; } Public stringtime{Get;Set; } Public stringdevicename{Get;Set; } Public stringfirmwaretype{Get;Set; } Public stringfirmwareversion{Get;Set; } Public stringlightintensity{Get;Set; } Public stringmajor{Get;Set; } PublicDateTime Createtime {Get;Set; } Public Override voidFill (System.Data.Common.DbDataReader dr) {Base. Fill (DR); } }
Object entity class
PublicList<beaconreceiveinfo>Select () {stringsql ="SELECT * from beaconreceive ORDER BY createtime desc LIMIT 0"; using(DbDataReader dr = Sqlitehelper.executereader (sql, SQLITEHELPER.CONNSTR,NULL, System.Data.CommandType.Text)) {List<BeaconReceiveInfo> LST =NewList<beaconreceiveinfo>(); while(Dr. Read ()) {Beaconreceiveinfo Info=NewBeaconreceiveinfo (); Info. Fill (DR); Lst. ADD (info); } returnlst; } }
Business Query Method
"2016-11-2" "persist in Learning" "Day17" "Automatically convert DataReader to entity info by reflection"