示例#1
0
        //public User CreateModel(IDataReader reader)
        //{
        //    return new User
        //    {
        //        UserName = ((string)reader["UserName"]).Trim(),
        //        Email = reader["Email"] == DBNull.Value ? default(string) : ((string)reader["Email"]).Trim(),
        //        Age = reader["Age"] == DBNull.Value ? default(int?) : (int)reader["Age"]
        //    };
        //}

        public User CreateModel(IDataReader reader, EasyDb db)
        {
            // db => model
            return(new User
            {
                UserName = ((string)reader["UserName"]).Trim(),
                Email = db.CheckDBNullAndConvertTo <string>(reader["Email"])?.Trim(),
                Age = db.CheckDBNullAndConvertTo <int?>(reader["Age"])
            });
        }