什么是实体类就不说了吧,我们可以把他简单的理解为将表的字段映射为类,字段名对应属性,用来做抽象封装
比如一个简单的汽车的的实体类
public class 汽车{
private _颜色;
public 颜色
{
get{return _颜色;}
set{_颜色=value;}
}
.....
}
疯狂代码可以自动生成实体类,含实体枚举,泛型比较等,很方便
这里以DZ论坛的一个POST表为例子生成实体类方法
代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
#region 修改日志
/*
----------------------------------------------------------------------------------------------------
-- 类创建时间: 星期四, 2008年9月11日 11:36:49
-- Created By:CrazyCoder 乔松涛
-- 目的:表Forum_Topics的实体类TopicsInfo 以及实体接口 比较等
-- 表说明:
-- 备注:该类以及基类所有方法由"疯狂代码"代码生成器创建 www.crazycoder.cn
-- mail:[email protected]
-- Msn:[email protected]
-- QQ:9095230
-- www.crazycoder.cn
----------------------------------------------------------------------------------------------------
*/
#endregion
namespace CrazyCoder.Entities.Forum
{
/// <summary>
/// 数据表Forum_Topics实体类基类 主键PK_Forum_topics 外键列表为 自增字段 tidInt32 唯一字段为:
/// </summary>
[Serializable]
public partial class TopicsInfo : EntitiesBase,IDataEntities,ITopicsInfo
{
#region 变量
private static string _tableName = "Forum_Topics";
/// <summary>
/// 实体的数据表名
/// </summary>
public static string TableName
{
get { return _tableName; }
}
private static string[] _tableColumns;//数据表 中的字段数组
/// <summary>
/// 数据表 中的字段数组
/// </summary>
public static string[] TableColumns
{
get {
_tableColumns = new string[28]{"Tid","Fid","Iconid","Typeid","Readperm","Price","Poster","Posterid","Title","Postdatetime","Lastpost","Lastpostid","Lastposter","Lastposterid","Views","Replies","Displayorder","Highlight","Digest","Rate","Hide","Poll","Attachment","Moderated","Closed","Magic","Identify","Special"};
return _tableColumns; }
}
/// <summary>
/// 实体类名
/// </summary>
public static string EntitiesClassName
{
get { return "TopicsInfo"; }
}
/// <summary>
/// 实体类基类名
/// </summary>
public static string EntitiesBaseClassName
{
get { return "TopicsInfoBase"; }
}
#endregion
#region 构造函数
/// <summary>
/// 默认构造函数 创建新的实例
/// </summary>
public TopicsInfo()
{
}
#region 构造函数,含所有参数
/// <summary>
/// 构造函数 创建新的实例
/// </summary>
/// <param name="_tid"></param>
/// <param name="_fid"></param>
/// <param name="_iconid"></param>
/// <param name="_typeid"></param>
/// <param name="_readperm"></param>
/// <param name="_price"></param>
/// <param name="_poster"></param>
/// <param name="_posterid"></param>
/// <param name="_title"></param>
/// <param name="_postdatetime"></param>
/// <param name="_lastpost"></param>
/// <param name="_lastpostid"></param>
/// <param name="_lastposter"></param>
/// <param name="_lastposterid"></param>
/// <param name="_views"></param>
/// <param name="_replies"></param>
/// <param name="_displayorder"></param>
/// <param name="_highlight"></param>
/// <param name="_digest"></param>
/// <param name="_rate"></param>
/// <param name="_hide"></param>
/// <param name="_poll"></param>
/// <param name="_attachment"></param>
/// <param name="_moderated"></param>
/// <param name="_closed"></param>
/// <param name="_magic"></param>
/// <param name="_identify"></param>
/// <param name="_special"></param>
public TopicsInfo(System.Int32 _tid,System.Int16 _fid,System.Byte _iconid,System.Int32 _typeid,System.Int32 _readperm,System.Int16 _price,System.String _poster,System.Int32 _posterid,System.String _title,System.DateTime _postdatetime,System.DateTime _lastpost,System.Int32 _lastpostid,System.String _lastposter,System.Int32 _lastposterid,System.Int32 _views,System.Int32 _replies,System.Int32 _displayorder,System.String _highlight,System.Byte _digest,System.Int32 _rate,System.Int32 _hide,System.Int32 _poll,System.Int32 _attachment,System.Byte _moderated,System.Int32 _closed,System.Int32 _magic,System.Int32 _identify,System.Byte _special)
{
this._tid = _tid;
this._fid = _fid;
this._iconid = _iconid;
this._typeid = _typeid;
this._readperm = _readperm;
this._price = _price;
this._poster = _poster;
this._posterid = _posterid;
this._title = _title;
this._postdatetime = _postdatetime;
this._lastpost = _lastpost;
this._lastpostid = _lastpostid;
this._lastposter = _lastposter;
this._lastposterid = _lastposterid;
this._views = _views;
this._replies = _replies;
this._displayorder = _displayorder;
this._highlight = _highlight;
this._digest = _digest;
this._rate = _rate;
this._hide = _hide;
this._poll = _poll;
this._attachment = _attachment;
this._moderated = _moderated;
this._closed = _closed;
this._magic = _magic;
this._identify = _identify;
this._special = _special;
}
#endregion
#endregion
#region 通过数据构造函数 IDataRecord DataRow DataRowView
#region 使用只读只进的数据流的构造函数 TopicsInfo(IDataRecord dr)
/// <summary>
/// 使用只读只进的数据流的构造函数
/// </summary>
/// <param name="dr">只读只进的数据流</param>
public TopicsInfo(IDataRecord dr)
{
string rowIndexName = dr.GetName(0);
if (!string.IsNullOrEmpty(rowIndexName) && rowIndexName.ToLower() == "rowindex")
{
//如果返回RowIndex
this.RowIndex = (long)dr[0];
}
this._tid = dr["Tid"] == DBNull.Value ? 0 : (System.Int32)dr["Tid"]; // 数据类型int 大小4 不允许空值
this._fid = dr["Fid"] == DBNull.Value ? 0 : (System.Int16)dr["Fid"]; // 数据类型smallint 大小2 不允许空值
this._iconid = dr["Iconid"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Iconid"]; // 数据类型tinyint 大小1 不允许空值
this._typeid = dr["Typeid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Typeid"]; // 数据类型int 大小4 不允许空值
this._readperm = dr["Readperm"] == DBNull.Value ? (int)0 : (System.Int32)dr["Readperm"]; // 数据类型int 大小4 不允许空值
this._price = dr["Price"] == DBNull.Value ? (short)0 : (System.Int16)dr["Price"]; // 数据类型smallint 大小2 不允许空值
this._poster = dr["Poster"] == DBNull.Value ? "" : (System.String)dr["Poster"]; // 数据类型nchar 大小20 不允许空值
this._posterid = dr["Posterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Posterid"]; // 数据类型int 大小4 不允许空值
this._title = dr["Title"] == DBNull.Value ? null : (System.String)dr["Title"]; // 数据类型nchar 大小60 不允许空值
this._postdatetime = dr["Postdatetime"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Postdatetime"]; // 数据类型datetime 大小8 不允许空值
this._lastpost = dr["Lastpost"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Lastpost"]; // 数据类型datetime 大小8 不允许空值
this._lastpostid = dr["Lastpostid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastpostid"]; // 数据类型int 大小4 不允许空值
this._lastposter = dr["Lastposter"] == DBNull.Value ? "" : (System.String)dr["Lastposter"]; // 数据类型nchar 大小20 不允许空值
this._lastposterid = dr["Lastposterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastposterid"]; // 数据类型int 大小4 不允许空值
this._views = dr["Views"] == DBNull.Value ? (int)0 : (System.Int32)dr["Views"]; // 数据类型int 大小4 不允许空值
this._replies = dr["Replies"] == DBNull.Value ? (int)0 : (System.Int32)dr["Replies"]; // 数据类型int 大小4 不允许空值
this._displayorder = dr["Displayorder"] == DBNull.Value ? (int)0 : (System.Int32)dr["Displayorder"]; // 数据类型int 大小4 不允许空值
this._highlight = dr["Highlight"] == DBNull.Value ? "" : (System.String)dr["Highlight"]; // 数据类型varchar 大小500 不允许空值
this._digest = dr["Digest"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Digest"]; // 数据类型tinyint 大小1 不允许空值
this._rate = dr["Rate"] == DBNull.Value ? (int)0 : (System.Int32)dr["Rate"]; // 数据类型int 大小4 不允许空值
this._hide = dr["Hide"] == DBNull.Value ? (int)0 : (System.Int32)dr["Hide"]; // 数据类型int 大小4 不允许空值
this._poll = dr["Poll"] == DBNull.Value ? (int)0 : (System.Int32)dr["Poll"]; // 数据类型int 大小4 不允许空值
this._attachment = dr["Attachment"] == DBNull.Value ? (int)0 : (System.Int32)dr["Attachment"]; // 数据类型int 大小4 不允许空值
this._moderated = dr["Moderated"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Moderated"]; // 数据类型tinyint 大小1 不允许空值
this._closed = dr["Closed"] == DBNull.Value ? (int)0 : (System.Int32)dr["Closed"]; // 数据类型int 大小4 不允许空值
this._magic = dr["Magic"] == DBNull.Value ? (int)0 : (System.Int32)dr["Magic"]; // 数据类型int 大小4 不允许空值
this._identify = dr["Identify"] == DBNull.Value ? (int)0 : (System.Int32)dr["Identify"]; // 数据类型int 大小4 不允许空值
this._special = dr["Special"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Special"]; // 数据类型tinyint 大小1 不允许空值
}
#endregion
#region 使用只读只进的数据流的构造函数TopicsInfo(IDataRecord dr, string[] columnNames)
/// <summary>
/// 使用只读只进的数据流的构造函数
/// </summary>
/// <param name="dr">只读只进的数据流</param>
/// <param name="columnNames">需要实例化的字段列表</param>
public TopicsInfo(IDataRecord dr, string[] columnNames)
{
if (columnNames == null || columnNames.Length <= 0)
return;
string rowIndexName = dr.GetName(0);
if (!string.IsNullOrEmpty(rowIndexName) && rowIndexName.ToLower() == "rowindex")
{
this.RowIndex = (long)dr[0];
}
foreach (string columnName in columnNames)
{
if (!string.IsNullOrEmpty(columnName))
{
switch (columnName.ToLower())
{
case "tid":
this._tid = dr["Tid"] == DBNull.Value ? 0 : (System.Int32)dr["Tid"]; // 数据类型int 大小4 不允许空值
break;
case "fid":
this._fid = dr["Fid"] == DBNull.Value ? 0 : (System.Int16)dr["Fid"]; // 数据类型smallint 大小2 不允许空值
break;
case "iconid":
this._iconid = dr["Iconid"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Iconid"]; // 数据类型tinyint 大小1 不允许空值
break;
case "typeid":
this._typeid = dr["Typeid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Typeid"]; // 数据类型int 大小4 不允许空值
break;
case "readperm":
this._readperm = dr["Readperm"] == DBNull.Value ? (int)0 : (System.Int32)dr["Readperm"]; // 数据类型int 大小4 不允许空值
break;
case "price":
this._price = dr["Price"] == DBNull.Value ? (short)0 : (System.Int16)dr["Price"]; // 数据类型smallint 大小2 不允许空值
break;
case "poster":
this._poster = dr["Poster"] == DBNull.Value ? "" : (System.String)dr["Poster"]; // 数据类型nchar 大小20 不允许空值
break;
case "posterid":
this._posterid = dr["Posterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Posterid"]; // 数据类型int 大小4 不允许空值
break;
case "title":
this._title = dr["Title"] == DBNull.Value ? null : (System.String)dr["Title"]; // 数据类型nchar 大小60 不允许空值
break;
case "postdatetime":
this._postdatetime = dr["Postdatetime"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Postdatetime"]; // 数据类型datetime 大小8 不允许空值
break;
case "lastpost":
this._lastpost = dr["Lastpost"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Lastpost"]; // 数据类型datetime 大小8 不允许空值
break;
case "lastpostid":
this._lastpostid = dr["Lastpostid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastpostid"]; // 数据类型int 大小4 不允许空值
break;
case "lastposter":
this._lastposter = dr["Lastposter"] == DBNull.Value ? "" : (System.String)dr["Lastposter"]; // 数据类型nchar 大小20 不允许空值
break;
case "lastposterid":
this._lastposterid = dr["Lastposterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastposterid"]; // 数据类型int 大小4 不允许空值
break;
case "views":
this._views = dr["Views"] == DBNull.Value ? (int)0 : (System.Int32)dr["Views"]; // 数据类型int 大小4 不允许空值
break;
case "replies":
this._replies = dr["Replies"] == DBNull.Value ? (int)0 : (System.Int32)dr["Replies"]; // 数据类型int 大小4 不允许空值
break;
case "displayorder":
this._displayorder = dr["Displayorder"] == DBNull.Value ? (int)0 : (System.Int32)dr["Displayorder"]; // 数据类型int 大小4 不允许空值
break;
case "highlight":
this._highlight = dr["Highlight"] == DBNull.Value ? "" : (System.String)dr["Highlight"]; // 数据类型varchar 大小500 不允许空值
break;
case "digest":
this._digest = dr["Digest"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Digest"]; // 数据类型tinyint 大小1 不允许空值
break;
case "rate":
this._rate = dr["Rate"] == DBNull.Value ? (int)0 : (System.Int32)dr["Rate"]; // 数据类型int 大小4 不允许空值
break;
case "hide":
this._hide = dr["Hide"] == DBNull.Value ? (int)0 : (System.Int32)dr["Hide"]; // 数据类型int 大小4 不允许空值
break;
case "poll":
this._poll = dr["Poll"] == DBNull.Value ? (int)0 : (System.Int32)dr["Poll"]; // 数据类型int 大小4 不允许空值
break;
case "attachment":
this._attachment = dr["Attachment"] == DBNull.Value ? (int)0 : (System.Int32)dr["Attachment"]; // 数据类型int 大小4 不允许空值
break;
case "moderated":
this._moderated = dr["Moderated"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Moderated"]; // 数据类型tinyint 大小1 不允许空值
break;
case "closed":
this._closed = dr["Closed"] == DBNull.Value ? (int)0 : (System.Int32)dr["Closed"]; // 数据类型int 大小4 不允许空值
break;
case "magic":
this._magic = dr["Magic"] == DBNull.Value ? (int)0 : (System.Int32)dr["Magic"]; // 数据类型int 大小4 不允许空值
break;
case "identify":
this._identify = dr["Identify"] == DBNull.Value ? (int)0 : (System.Int32)dr["Identify"]; // 数据类型int 大小4 不允许空值
break;
case "special":
this._special = dr["Special"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Special"]; // 数据类型tinyint 大小1 不允许空值
break;
default:
break;
}
}
}
}
#endregion
#region 使用只读只进的数据流的构造函数TopicsInfo(IDataRecord dr, TopicsInfoEnumeration[] columnNames)
/// <summary>
/// 使用只读只进的数据流的构造函数
/// </summary>
/// <param name="dr">只读只进的数据流</param>
/// <param name="columnNames">需要实例化的字段列表</param>
public TopicsInfo(IDataRecord dr, TopicsInfoEnumeration[] columnNames)
{
if (columnNames == null || columnNames.Length <= 0)
return;
string rowIndexName = dr.GetName(0);
if (!string.IsNullOrEmpty(rowIndexName) && rowIndexName.ToLower() == "rowindex")
{
this.RowIndex = (long)dr[0];
}
foreach (TopicsInfoEnumeration columnName in columnNames)
{
switch (columnName)
{
case TopicsInfoEnumeration.Tid:
this._tid = dr["Tid"] == DBNull.Value ? 0 : (System.Int32)dr["Tid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Fid:
this._fid = dr["Fid"] == DBNull.Value ? 0 : (System.Int16)dr["Fid"]; // 数据类型smallint 大小2 不允许空值
break;
case TopicsInfoEnumeration.Iconid:
this._iconid = dr["Iconid"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Iconid"]; // 数据类型tinyint 大小1 不允许空值
break;
case TopicsInfoEnumeration.Typeid:
this._typeid = dr["Typeid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Typeid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Readperm:
this._readperm = dr["Readperm"] == DBNull.Value ? (int)0 : (System.Int32)dr["Readperm"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Price:
this._price = dr["Price"] == DBNull.Value ? (short)0 : (System.Int16)dr["Price"]; // 数据类型smallint 大小2 不允许空值
break;
case TopicsInfoEnumeration.Poster:
this._poster = dr["Poster"] == DBNull.Value ? "" : (System.String)dr["Poster"]; // 数据类型nchar 大小20 不允许空值
break;
case TopicsInfoEnumeration.Posterid:
this._posterid = dr["Posterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Posterid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Title:
this._title = dr["Title"] == DBNull.Value ? null : (System.String)dr["Title"]; // 数据类型nchar 大小60 不允许空值
break;
case TopicsInfoEnumeration.Postdatetime:
this._postdatetime = dr["Postdatetime"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Postdatetime"]; // 数据类型datetime 大小8 不允许空值
break;
case TopicsInfoEnumeration.Lastpost:
this._lastpost = dr["Lastpost"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Lastpost"]; // 数据类型datetime 大小8 不允许空值
break;
case TopicsInfoEnumeration.Lastpostid:
this._lastpostid = dr["Lastpostid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastpostid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Lastposter:
this._lastposter = dr["Lastposter"] == DBNull.Value ? "" : (System.String)dr["Lastposter"]; // 数据类型nchar 大小20 不允许空值
break;
case TopicsInfoEnumeration.Lastposterid:
this._lastposterid = dr["Lastposterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastposterid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Views:
this._views = dr["Views"] == DBNull.Value ? (int)0 : (System.Int32)dr["Views"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Replies:
this._replies = dr["Replies"] == DBNull.Value ? (int)0 : (System.Int32)dr["Replies"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Displayorder:
this._displayorder = dr["Displayorder"] == DBNull.Value ? (int)0 : (System.Int32)dr["Displayorder"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Highlight:
this._highlight = dr["Highlight"] == DBNull.Value ? "" : (System.String)dr["Highlight"]; // 数据类型varchar 大小500 不允许空值
break;
case TopicsInfoEnumeration.Digest:
this._digest = dr["Digest"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Digest"]; // 数据类型tinyint 大小1 不允许空值
break;
case TopicsInfoEnumeration.Rate:
this._rate = dr["Rate"] == DBNull.Value ? (int)0 : (System.Int32)dr["Rate"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Hide:
this._hide = dr["Hide"] == DBNull.Value ? (int)0 : (System.Int32)dr["Hide"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Poll:
this._poll = dr["Poll"] == DBNull.Value ? (int)0 : (System.Int32)dr["Poll"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Attachment:
this._attachment = dr["Attachment"] == DBNull.Value ? (int)0 : (System.Int32)dr["Attachment"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Moderated:
this._moderated = dr["Moderated"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Moderated"]; // 数据类型tinyint 大小1 不允许空值
break;
case TopicsInfoEnumeration.Closed:
this._closed = dr["Closed"] == DBNull.Value ? (int)0 : (System.Int32)dr["Closed"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Magic:
this._magic = dr["Magic"] == DBNull.Value ? (int)0 : (System.Int32)dr["Magic"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Identify:
this._identify = dr["Identify"] == DBNull.Value ? (int)0 : (System.Int32)dr["Identify"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Special:
this._special = dr["Special"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Special"]; // 数据类型tinyint 大小1 不允许空值
break;
default:
break;
}
}
}
#endregion
#region 使用DataRow构造函数 TopicsInfo(DataRow dr)
/// <summary>
/// 使用DataRow构造函数
/// </summary>
/// <param name="dr">DataRow</param>
public TopicsInfo(DataRow dr)
{
this._tid = dr["Tid"] == DBNull.Value ? 0 : (System.Int32)dr["Tid"]; // 数据类型int 大小4 不允许空值
this._fid = dr["Fid"] == DBNull.Value ? 0 : (System.Int16)dr["Fid"]; // 数据类型smallint 大小2 不允许空值
this._iconid = dr["Iconid"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Iconid"]; // 数据类型tinyint 大小1 不允许空值
this._typeid = dr["Typeid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Typeid"]; // 数据类型int 大小4 不允许空值
this._readperm = dr["Readperm"] == DBNull.Value ? (int)0 : (System.Int32)dr["Readperm"]; // 数据类型int 大小4 不允许空值
this._price = dr["Price"] == DBNull.Value ? (short)0 : (System.Int16)dr["Price"]; // 数据类型smallint 大小2 不允许空值
this._poster = dr["Poster"] == DBNull.Value ? "" : (System.String)dr["Poster"]; // 数据类型nchar 大小20 不允许空值
this._posterid = dr["Posterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Posterid"]; // 数据类型int 大小4 不允许空值
this._title = dr["Title"] == DBNull.Value ? null : (System.String)dr["Title"]; // 数据类型nchar 大小60 不允许空值
this._postdatetime = dr["Postdatetime"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Postdatetime"]; // 数据类型datetime 大小8 不允许空值
this._lastpost = dr["Lastpost"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Lastpost"]; // 数据类型datetime 大小8 不允许空值
this._lastpostid = dr["Lastpostid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastpostid"]; // 数据类型int 大小4 不允许空值
this._lastposter = dr["Lastposter"] == DBNull.Value ? "" : (System.String)dr["Lastposter"]; // 数据类型nchar 大小20 不允许空值
this._lastposterid = dr["Lastposterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastposterid"]; // 数据类型int 大小4 不允许空值
this._views = dr["Views"] == DBNull.Value ? (int)0 : (System.Int32)dr["Views"]; // 数据类型int 大小4 不允许空值
this._replies = dr["Replies"] == DBNull.Value ? (int)0 : (System.Int32)dr["Replies"]; // 数据类型int 大小4 不允许空值
this._displayorder = dr["Displayorder"] == DBNull.Value ? (int)0 : (System.Int32)dr["Displayorder"]; // 数据类型int 大小4 不允许空值
this._highlight = dr["Highlight"] == DBNull.Value ? "" : (System.String)dr["Highlight"]; // 数据类型varchar 大小500 不允许空值
this._digest = dr["Digest"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Digest"]; // 数据类型tinyint 大小1 不允许空值
this._rate = dr["Rate"] == DBNull.Value ? (int)0 : (System.Int32)dr["Rate"]; // 数据类型int 大小4 不允许空值
this._hide = dr["Hide"] == DBNull.Value ? (int)0 : (System.Int32)dr["Hide"]; // 数据类型int 大小4 不允许空值
this._poll = dr["Poll"] == DBNull.Value ? (int)0 : (System.Int32)dr["Poll"]; // 数据类型int 大小4 不允许空值
this._attachment = dr["Attachment"] == DBNull.Value ? (int)0 : (System.Int32)dr["Attachment"]; // 数据类型int 大小4 不允许空值
this._moderated = dr["Moderated"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Moderated"]; // 数据类型tinyint 大小1 不允许空值
this._closed = dr["Closed"] == DBNull.Value ? (int)0 : (System.Int32)dr["Closed"]; // 数据类型int 大小4 不允许空值
this._magic = dr["Magic"] == DBNull.Value ? (int)0 : (System.Int32)dr["Magic"]; // 数据类型int 大小4 不允许空值
this._identify = dr["Identify"] == DBNull.Value ? (int)0 : (System.Int32)dr["Identify"]; // 数据类型int 大小4 不允许空值
this._special = dr["Special"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Special"]; // 数据类型tinyint 大小1 不允许空值
}
#endregion
#region 使用DataRow构造函数 TopicsInfo(DataRow dr, string[] columnNames)
/// <summary>
/// 使用DataRow构造函数
/// </summary>
/// <param name="dr">DataRow</param>
/// <param name="columnNames">需要实例化的字段列表</param>
public TopicsInfo(DataRow dr, string[] columnNames)
{
if (columnNames == null || columnNames.Length <= 0)
return;
foreach (string columnName in columnNames)
{
if (!string.IsNullOrEmpty(columnName))
{
switch (columnName.ToLower())
{
case "tid":
this._tid = dr["Tid"] == DBNull.Value ? 0 : (System.Int32)dr["Tid"]; // 数据类型int 大小4 不允许空值
break;
case "fid":
this._fid = dr["Fid"] == DBNull.Value ? 0 : (System.Int16)dr["Fid"]; // 数据类型smallint 大小2 不允许空值
break;
case "iconid":
this._iconid = dr["Iconid"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Iconid"]; // 数据类型tinyint 大小1 不允许空值
break;
case "typeid":
this._typeid = dr["Typeid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Typeid"]; // 数据类型int 大小4 不允许空值
break;
case "readperm":
this._readperm = dr["Readperm"] == DBNull.Value ? (int)0 : (System.Int32)dr["Readperm"]; // 数据类型int 大小4 不允许空值
break;
case "price":
this._price = dr["Price"] == DBNull.Value ? (short)0 : (System.Int16)dr["Price"]; // 数据类型smallint 大小2 不允许空值
break;
case "poster":
this._poster = dr["Poster"] == DBNull.Value ? "" : (System.String)dr["Poster"]; // 数据类型nchar 大小20 不允许空值
break;
case "posterid":
this._posterid = dr["Posterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Posterid"]; // 数据类型int 大小4 不允许空值
break;
case "title":
this._title = dr["Title"] == DBNull.Value ? null : (System.String)dr["Title"]; // 数据类型nchar 大小60 不允许空值
break;
case "postdatetime":
this._postdatetime = dr["Postdatetime"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Postdatetime"]; // 数据类型datetime 大小8 不允许空值
break;
case "lastpost":
this._lastpost = dr["Lastpost"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Lastpost"]; // 数据类型datetime 大小8 不允许空值
break;
case "lastpostid":
this._lastpostid = dr["Lastpostid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastpostid"]; // 数据类型int 大小4 不允许空值
break;
case "lastposter":
this._lastposter = dr["Lastposter"] == DBNull.Value ? "" : (System.String)dr["Lastposter"]; // 数据类型nchar 大小20 不允许空值
break;
case "lastposterid":
this._lastposterid = dr["Lastposterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastposterid"]; // 数据类型int 大小4 不允许空值
break;
case "views":
this._views = dr["Views"] == DBNull.Value ? (int)0 : (System.Int32)dr["Views"]; // 数据类型int 大小4 不允许空值
break;
case "replies":
this._replies = dr["Replies"] == DBNull.Value ? (int)0 : (System.Int32)dr["Replies"]; // 数据类型int 大小4 不允许空值
break;
case "displayorder":
this._displayorder = dr["Displayorder"] == DBNull.Value ? (int)0 : (System.Int32)dr["Displayorder"]; // 数据类型int 大小4 不允许空值
break;
case "highlight":
this._highlight = dr["Highlight"] == DBNull.Value ? "" : (System.String)dr["Highlight"]; // 数据类型varchar 大小500 不允许空值
break;
case "digest":
this._digest = dr["Digest"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Digest"]; // 数据类型tinyint 大小1 不允许空值
break;
case "rate":
this._rate = dr["Rate"] == DBNull.Value ? (int)0 : (System.Int32)dr["Rate"]; // 数据类型int 大小4 不允许空值
break;
case "hide":
this._hide = dr["Hide"] == DBNull.Value ? (int)0 : (System.Int32)dr["Hide"]; // 数据类型int 大小4 不允许空值
break;
case "poll":
this._poll = dr["Poll"] == DBNull.Value ? (int)0 : (System.Int32)dr["Poll"]; // 数据类型int 大小4 不允许空值
break;
case "attachment":
this._attachment = dr["Attachment"] == DBNull.Value ? (int)0 : (System.Int32)dr["Attachment"]; // 数据类型int 大小4 不允许空值
break;
case "moderated":
this._moderated = dr["Moderated"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Moderated"]; // 数据类型tinyint 大小1 不允许空值
break;
case "closed":
this._closed = dr["Closed"] == DBNull.Value ? (int)0 : (System.Int32)dr["Closed"]; // 数据类型int 大小4 不允许空值
break;
case "magic":
this._magic = dr["Magic"] == DBNull.Value ? (int)0 : (System.Int32)dr["Magic"]; // 数据类型int 大小4 不允许空值
break;
case "identify":
this._identify = dr["Identify"] == DBNull.Value ? (int)0 : (System.Int32)dr["Identify"]; // 数据类型int 大小4 不允许空值
break;
case "special":
this._special = dr["Special"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Special"]; // 数据类型tinyint 大小1 不允许空值
break;
default:
break;
}
}
}
}
#endregion
#region 使用DataRow构造函数 TopicsInfo(DataRow dr, TopicsInfoEnumeration[] columnNames)
/// <summary>
/// 使用DataRow构造函数
/// </summary>
/// <param name="dr">DataRow</param>
/// <param name="columnNames">需要实例化的字段列表</param>
public TopicsInfo(DataRow dr, TopicsInfoEnumeration[] columnNames)
{
if (columnNames == null || columnNames.Length <= 0)
return;
foreach (TopicsInfoEnumeration columnName in columnNames)
{
switch (columnName)
{
case TopicsInfoEnumeration.Tid:
this._tid = dr["Tid"] == DBNull.Value ? 0 : (System.Int32)dr["Tid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Fid:
this._fid = dr["Fid"] == DBNull.Value ? 0 : (System.Int16)dr["Fid"]; // 数据类型smallint 大小2 不允许空值
break;
case TopicsInfoEnumeration.Iconid:
this._iconid = dr["Iconid"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Iconid"]; // 数据类型tinyint 大小1 不允许空值
break;
case TopicsInfoEnumeration.Typeid:
this._typeid = dr["Typeid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Typeid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Readperm:
this._readperm = dr["Readperm"] == DBNull.Value ? (int)0 : (System.Int32)dr["Readperm"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Price:
this._price = dr["Price"] == DBNull.Value ? (short)0 : (System.Int16)dr["Price"]; // 数据类型smallint 大小2 不允许空值
break;
case TopicsInfoEnumeration.Poster:
this._poster = dr["Poster"] == DBNull.Value ? "" : (System.String)dr["Poster"]; // 数据类型nchar 大小20 不允许空值
break;
case TopicsInfoEnumeration.Posterid:
this._posterid = dr["Posterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Posterid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Title:
this._title = dr["Title"] == DBNull.Value ? null : (System.String)dr["Title"]; // 数据类型nchar 大小60 不允许空值
break;
case TopicsInfoEnumeration.Postdatetime:
this._postdatetime = dr["Postdatetime"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Postdatetime"]; // 数据类型datetime 大小8 不允许空值
break;
case TopicsInfoEnumeration.Lastpost:
this._lastpost = dr["Lastpost"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Lastpost"]; // 数据类型datetime 大小8 不允许空值
break;
case TopicsInfoEnumeration.Lastpostid:
this._lastpostid = dr["Lastpostid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastpostid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Lastposter:
this._lastposter = dr["Lastposter"] == DBNull.Value ? "" : (System.String)dr["Lastposter"]; // 数据类型nchar 大小20 不允许空值
break;
case TopicsInfoEnumeration.Lastposterid:
this._lastposterid = dr["Lastposterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastposterid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Views:
this._views = dr["Views"] == DBNull.Value ? (int)0 : (System.Int32)dr["Views"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Replies:
this._replies = dr["Replies"] == DBNull.Value ? (int)0 : (System.Int32)dr["Replies"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Displayorder:
this._displayorder = dr["Displayorder"] == DBNull.Value ? (int)0 : (System.Int32)dr["Displayorder"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Highlight:
this._highlight = dr["Highlight"] == DBNull.Value ? "" : (System.String)dr["Highlight"]; // 数据类型varchar 大小500 不允许空值
break;
case TopicsInfoEnumeration.Digest:
this._digest = dr["Digest"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Digest"]; // 数据类型tinyint 大小1 不允许空值
break;
case TopicsInfoEnumeration.Rate:
this._rate = dr["Rate"] == DBNull.Value ? (int)0 : (System.Int32)dr["Rate"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Hide:
this._hide = dr["Hide"] == DBNull.Value ? (int)0 : (System.Int32)dr["Hide"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Poll:
this._poll = dr["Poll"] == DBNull.Value ? (int)0 : (System.Int32)dr["Poll"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Attachment:
this._attachment = dr["Attachment"] == DBNull.Value ? (int)0 : (System.Int32)dr["Attachment"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Moderated:
this._moderated = dr["Moderated"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Moderated"]; // 数据类型tinyint 大小1 不允许空值
break;
case TopicsInfoEnumeration.Closed:
this._closed = dr["Closed"] == DBNull.Value ? (int)0 : (System.Int32)dr["Closed"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Magic:
this._magic = dr["Magic"] == DBNull.Value ? (int)0 : (System.Int32)dr["Magic"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Identify:
this._identify = dr["Identify"] == DBNull.Value ? (int)0 : (System.Int32)dr["Identify"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Special:
this._special = dr["Special"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Special"]; // 数据类型tinyint 大小1 不允许空值
break;
default:
break;
}
}
}
#endregion
#region 使用DataRowView构造函数 TopicsInfo(DataRowView dr)
/// <summary>
/// 使用DataRowView构造函数
/// </summary>
/// <param name="dr">DataRowView</param>
public TopicsInfo(DataRowView dr)
{
this._tid = dr["Tid"] == DBNull.Value ? 0 : (System.Int32)dr["Tid"]; // 数据类型int 大小4 不允许空值
this._fid = dr["Fid"] == DBNull.Value ? 0 : (System.Int16)dr["Fid"]; // 数据类型smallint 大小2 不允许空值
this._iconid = dr["Iconid"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Iconid"]; // 数据类型tinyint 大小1 不允许空值
this._typeid = dr["Typeid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Typeid"]; // 数据类型int 大小4 不允许空值
this._readperm = dr["Readperm"] == DBNull.Value ? (int)0 : (System.Int32)dr["Readperm"]; // 数据类型int 大小4 不允许空值
this._price = dr["Price"] == DBNull.Value ? (short)0 : (System.Int16)dr["Price"]; // 数据类型smallint 大小2 不允许空值
this._poster = dr["Poster"] == DBNull.Value ? "" : (System.String)dr["Poster"]; // 数据类型nchar 大小20 不允许空值
this._posterid = dr["Posterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Posterid"]; // 数据类型int 大小4 不允许空值
this._title = dr["Title"] == DBNull.Value ? null : (System.String)dr["Title"]; // 数据类型nchar 大小60 不允许空值
this._postdatetime = dr["Postdatetime"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Postdatetime"]; // 数据类型datetime 大小8 不允许空值
this._lastpost = dr["Lastpost"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Lastpost"]; // 数据类型datetime 大小8 不允许空值
this._lastpostid = dr["Lastpostid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastpostid"]; // 数据类型int 大小4 不允许空值
this._lastposter = dr["Lastposter"] == DBNull.Value ? "" : (System.String)dr["Lastposter"]; // 数据类型nchar 大小20 不允许空值
this._lastposterid = dr["Lastposterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastposterid"]; // 数据类型int 大小4 不允许空值
this._views = dr["Views"] == DBNull.Value ? (int)0 : (System.Int32)dr["Views"]; // 数据类型int 大小4 不允许空值
this._replies = dr["Replies"] == DBNull.Value ? (int)0 : (System.Int32)dr["Replies"]; // 数据类型int 大小4 不允许空值
this._displayorder = dr["Displayorder"] == DBNull.Value ? (int)0 : (System.Int32)dr["Displayorder"]; // 数据类型int 大小4 不允许空值
this._highlight = dr["Highlight"] == DBNull.Value ? "" : (System.String)dr["Highlight"]; // 数据类型varchar 大小500 不允许空值
this._digest = dr["Digest"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Digest"]; // 数据类型tinyint 大小1 不允许空值
this._rate = dr["Rate"] == DBNull.Value ? (int)0 : (System.Int32)dr["Rate"]; // 数据类型int 大小4 不允许空值
this._hide = dr["Hide"] == DBNull.Value ? (int)0 : (System.Int32)dr["Hide"]; // 数据类型int 大小4 不允许空值
this._poll = dr["Poll"] == DBNull.Value ? (int)0 : (System.Int32)dr["Poll"]; // 数据类型int 大小4 不允许空值
this._attachment = dr["Attachment"] == DBNull.Value ? (int)0 : (System.Int32)dr["Attachment"]; // 数据类型int 大小4 不允许空值
this._moderated = dr["Moderated"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Moderated"]; // 数据类型tinyint 大小1 不允许空值
this._closed = dr["Closed"] == DBNull.Value ? (int)0 : (System.Int32)dr["Closed"]; // 数据类型int 大小4 不允许空值
this._magic = dr["Magic"] == DBNull.Value ? (int)0 : (System.Int32)dr["Magic"]; // 数据类型int 大小4 不允许空值
this._identify = dr["Identify"] == DBNull.Value ? (int)0 : (System.Int32)dr["Identify"]; // 数据类型int 大小4 不允许空值
this._special = dr["Special"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Special"]; // 数据类型tinyint 大小1 不允许空值
}
#endregion
#region 使用DataRowView构造函数 TopicsInfo(DataRowView dr, string[] columnNames)
/// <summary>
/// 使用DataRowView构造函数
/// </summary>
/// <param name="dr">DataRowView</param>
/// <param name="columnNames">需要实例化的字段列表</param>
public TopicsInfo(DataRowView dr, string[] columnNames)
{
if (columnNames == null || columnNames.Length <= 0)
return;
foreach (string columnName in columnNames)
{
if (!string.IsNullOrEmpty(columnName))
{
switch (columnName.ToLower())
{
case "tid":
this._tid = dr["Tid"] == DBNull.Value ? 0 : (System.Int32)dr["Tid"]; // 数据类型int 大小4 不允许空值
break;
case "fid":
this._fid = dr["Fid"] == DBNull.Value ? 0 : (System.Int16)dr["Fid"]; // 数据类型smallint 大小2 不允许空值
break;
case "iconid":
this._iconid = dr["Iconid"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Iconid"]; // 数据类型tinyint 大小1 不允许空值
break;
case "typeid":
this._typeid = dr["Typeid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Typeid"]; // 数据类型int 大小4 不允许空值
break;
case "readperm":
this._readperm = dr["Readperm"] == DBNull.Value ? (int)0 : (System.Int32)dr["Readperm"]; // 数据类型int 大小4 不允许空值
break;
case "price":
this._price = dr["Price"] == DBNull.Value ? (short)0 : (System.Int16)dr["Price"]; // 数据类型smallint 大小2 不允许空值
break;
case "poster":
this._poster = dr["Poster"] == DBNull.Value ? "" : (System.String)dr["Poster"]; // 数据类型nchar 大小20 不允许空值
break;
case "posterid":
this._posterid = dr["Posterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Posterid"]; // 数据类型int 大小4 不允许空值
break;
case "title":
this._title = dr["Title"] == DBNull.Value ? null : (System.String)dr["Title"]; // 数据类型nchar 大小60 不允许空值
break;
case "postdatetime":
this._postdatetime = dr["Postdatetime"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Postdatetime"]; // 数据类型datetime 大小8 不允许空值
break;
case "lastpost":
this._lastpost = dr["Lastpost"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Lastpost"]; // 数据类型datetime 大小8 不允许空值
break;
case "lastpostid":
this._lastpostid = dr["Lastpostid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastpostid"]; // 数据类型int 大小4 不允许空值
break;
case "lastposter":
this._lastposter = dr["Lastposter"] == DBNull.Value ? "" : (System.String)dr["Lastposter"]; // 数据类型nchar 大小20 不允许空值
break;
case "lastposterid":
this._lastposterid = dr["Lastposterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastposterid"]; // 数据类型int 大小4 不允许空值
break;
case "views":
this._views = dr["Views"] == DBNull.Value ? (int)0 : (System.Int32)dr["Views"]; // 数据类型int 大小4 不允许空值
break;
case "replies":
this._replies = dr["Replies"] == DBNull.Value ? (int)0 : (System.Int32)dr["Replies"]; // 数据类型int 大小4 不允许空值
break;
case "displayorder":
this._displayorder = dr["Displayorder"] == DBNull.Value ? (int)0 : (System.Int32)dr["Displayorder"]; // 数据类型int 大小4 不允许空值
break;
case "highlight":
this._highlight = dr["Highlight"] == DBNull.Value ? "" : (System.String)dr["Highlight"]; // 数据类型varchar 大小500 不允许空值
break;
case "digest":
this._digest = dr["Digest"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Digest"]; // 数据类型tinyint 大小1 不允许空值
break;
case "rate":
this._rate = dr["Rate"] == DBNull.Value ? (int)0 : (System.Int32)dr["Rate"]; // 数据类型int 大小4 不允许空值
break;
case "hide":
this._hide = dr["Hide"] == DBNull.Value ? (int)0 : (System.Int32)dr["Hide"]; // 数据类型int 大小4 不允许空值
break;
case "poll":
this._poll = dr["Poll"] == DBNull.Value ? (int)0 : (System.Int32)dr["Poll"]; // 数据类型int 大小4 不允许空值
break;
case "attachment":
this._attachment = dr["Attachment"] == DBNull.Value ? (int)0 : (System.Int32)dr["Attachment"]; // 数据类型int 大小4 不允许空值
break;
case "moderated":
this._moderated = dr["Moderated"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Moderated"]; // 数据类型tinyint 大小1 不允许空值
break;
case "closed":
this._closed = dr["Closed"] == DBNull.Value ? (int)0 : (System.Int32)dr["Closed"]; // 数据类型int 大小4 不允许空值
break;
case "magic":
this._magic = dr["Magic"] == DBNull.Value ? (int)0 : (System.Int32)dr["Magic"]; // 数据类型int 大小4 不允许空值
break;
case "identify":
this._identify = dr["Identify"] == DBNull.Value ? (int)0 : (System.Int32)dr["Identify"]; // 数据类型int 大小4 不允许空值
break;
case "special":
this._special = dr["Special"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Special"]; // 数据类型tinyint 大小1 不允许空值
break;
default:
break;
}
}
}
}
#endregion
#region 使用DataRowView构造函数 TopicsInfo(DataRowView dr, TopicsInfoEnumeration[] columnNames)
/// <summary>
/// 使用DataRowView构造函数
/// </summary>
/// <param name="dr">DataRowView</param>
/// <param name="columnNames">需要实例化的字段列表</param>
public TopicsInfo(DataRowView dr, TopicsInfoEnumeration[] columnNames)
{
if (columnNames == null || columnNames.Length <= 0)
return;
foreach (TopicsInfoEnumeration columnName in columnNames)
{
switch (columnName)
{
case TopicsInfoEnumeration.Tid:
this._tid = dr["Tid"] == DBNull.Value ? 0 : (System.Int32)dr["Tid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Fid:
this._fid = dr["Fid"] == DBNull.Value ? 0 : (System.Int16)dr["Fid"]; // 数据类型smallint 大小2 不允许空值
break;
case TopicsInfoEnumeration.Iconid:
this._iconid = dr["Iconid"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Iconid"]; // 数据类型tinyint 大小1 不允许空值
break;
case TopicsInfoEnumeration.Typeid:
this._typeid = dr["Typeid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Typeid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Readperm:
this._readperm = dr["Readperm"] == DBNull.Value ? (int)0 : (System.Int32)dr["Readperm"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Price:
this._price = dr["Price"] == DBNull.Value ? (short)0 : (System.Int16)dr["Price"]; // 数据类型smallint 大小2 不允许空值
break;
case TopicsInfoEnumeration.Poster:
this._poster = dr["Poster"] == DBNull.Value ? "" : (System.String)dr["Poster"]; // 数据类型nchar 大小20 不允许空值
break;
case TopicsInfoEnumeration.Posterid:
this._posterid = dr["Posterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Posterid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Title:
this._title = dr["Title"] == DBNull.Value ? null : (System.String)dr["Title"]; // 数据类型nchar 大小60 不允许空值
break;
case TopicsInfoEnumeration.Postdatetime:
this._postdatetime = dr["Postdatetime"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Postdatetime"]; // 数据类型datetime 大小8 不允许空值
break;
case TopicsInfoEnumeration.Lastpost:
this._lastpost = dr["Lastpost"] == DBNull.Value ? DateTime.Now : (System.DateTime)dr["Lastpost"]; // 数据类型datetime 大小8 不允许空值
break;
case TopicsInfoEnumeration.Lastpostid:
this._lastpostid = dr["Lastpostid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastpostid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Lastposter:
this._lastposter = dr["Lastposter"] == DBNull.Value ? "" : (System.String)dr["Lastposter"]; // 数据类型nchar 大小20 不允许空值
break;
case TopicsInfoEnumeration.Lastposterid:
this._lastposterid = dr["Lastposterid"] == DBNull.Value ? (int)0 : (System.Int32)dr["Lastposterid"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Views:
this._views = dr["Views"] == DBNull.Value ? (int)0 : (System.Int32)dr["Views"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Replies:
this._replies = dr["Replies"] == DBNull.Value ? (int)0 : (System.Int32)dr["Replies"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Displayorder:
this._displayorder = dr["Displayorder"] == DBNull.Value ? (int)0 : (System.Int32)dr["Displayorder"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Highlight:
this._highlight = dr["Highlight"] == DBNull.Value ? "" : (System.String)dr["Highlight"]; // 数据类型varchar 大小500 不允许空值
break;
case TopicsInfoEnumeration.Digest:
this._digest = dr["Digest"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Digest"]; // 数据类型tinyint 大小1 不允许空值
break;
case TopicsInfoEnumeration.Rate:
this._rate = dr["Rate"] == DBNull.Value ? (int)0 : (System.Int32)dr["Rate"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Hide:
this._hide = dr["Hide"] == DBNull.Value ? (int)0 : (System.Int32)dr["Hide"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Poll:
this._poll = dr["Poll"] == DBNull.Value ? (int)0 : (System.Int32)dr["Poll"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Attachment:
this._attachment = dr["Attachment"] == DBNull.Value ? (int)0 : (System.Int32)dr["Attachment"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Moderated:
this._moderated = dr["Moderated"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Moderated"]; // 数据类型tinyint 大小1 不允许空值
break;
case TopicsInfoEnumeration.Closed:
this._closed = dr["Closed"] == DBNull.Value ? (int)0 : (System.Int32)dr["Closed"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Magic:
this._magic = dr["Magic"] == DBNull.Value ? (int)0 : (System.Int32)dr["Magic"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Identify:
this._identify = dr["Identify"] == DBNull.Value ? (int)0 : (System.Int32)dr["Identify"]; // 数据类型int 大小4 不允许空值
break;
case TopicsInfoEnumeration.Special:
this._special = dr["Special"] == DBNull.Value ? (byte)0 : (System.Byte)dr["Special"]; // 数据类型tinyint 大小1 不允许空值
break;
default:
break;
}
}
}
#endregion
#endregion
#region 数据列属性
private System.Int32 _tid;//
private System.Int16 _fid;//
private System.Byte _iconid;//
private System.Int32 _typeid;//
private System.Int32 _readperm;//
private System.Int16 _price;//
private System.String _poster;//
private System.Int32 _posterid;//
private System.String _title;//
private System.DateTime _postdatetime;//
private System.DateTime _lastpost;//
private System.Int32 _lastpostid;//
private System.String _lastposter;//
private System.Int32 _lastposterid;//
private System.Int32 _views;//
private System.Int32 _replies;//
private System.Int32 _displayorder;//
private System.String _highlight;//
private System.Byte _digest;//
private System.Int32 _rate;//
private System.Int32 _hide;//
private System.Int32 _poll;//
private System.Int32 _attachment;//
private System.Byte _moderated;//
private System.Int32 _closed;//
private System.Int32 _magic;//
private System.Int32 _identify;//
private System.Byte _special;//
/// <summary>
/// 获取或者设置 Tid 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Tid
{
get { return _tid; }
set {
if (_tid == value)
{
return;
}
_tid = value; }
}
/// <summary>
/// 获取或者设置 Fid 属性.
///
/// </summary>
/// <value>类型是 smallint.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int16 Fid
{
get { return _fid; }
set {
if (_fid == value)
{
return;
}
_fid = value; }
}
/// <summary>
/// 获取或者设置 Iconid 属性.
///
/// </summary>
/// <value>类型是 tinyint.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Byte Iconid
{
get { return _iconid; }
set {
if (_iconid == value)
{
return;
}
_iconid = value; }
}
/// <summary>
/// 获取或者设置 Typeid 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Typeid
{
get { return _typeid; }
set {
if (_typeid == value)
{
return;
}
_typeid = value; }
}
/// <summary>
/// 获取或者设置 Readperm 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Readperm
{
get { return _readperm; }
set {
if (_readperm == value)
{
return;
}
_readperm = value; }
}
/// <summary>
/// 获取或者设置 Price 属性.
///
/// </summary>
/// <value>类型是 smallint.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int16 Price
{
get { return _price; }
set {
if (_price == value)
{
return;
}
_price = value; }
}
/// <summary>
/// 获取或者设置 Poster 属性.
///
/// </summary>
/// <value>类型是 nchar.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.String Poster
{
get { return _poster; }
set {
if (_poster == value)
{
return;
}
_poster = value; }
}
/// <summary>
/// 获取或者设置 Posterid 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Posterid
{
get { return _posterid; }
set {
if (_posterid == value)
{
return;
}
_posterid = value; }
}
/// <summary>
/// 获取或者设置 Title 属性.
///
/// </summary>
/// <value>类型是 nchar.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.String Title
{
get { return _title; }
set {
if (_title == value)
{
return;
}
_title = value; }
}
/// <summary>
/// 获取或者设置 Postdatetime 属性.
///
/// </summary>
/// <value>类型是 datetime.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.DateTime Postdatetime
{
get { return _postdatetime; }
set {
if (_postdatetime == value)
{
return;
}
_postdatetime = value; }
}
/// <summary>
/// 获取或者设置 Lastpost 属性.
///
/// </summary>
/// <value>类型是 datetime.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.DateTime Lastpost
{
get { return _lastpost; }
set {
if (_lastpost == value)
{
return;
}
_lastpost = value; }
}
/// <summary>
/// 获取或者设置 Lastpostid 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Lastpostid
{
get { return _lastpostid; }
set {
if (_lastpostid == value)
{
return;
}
_lastpostid = value; }
}
/// <summary>
/// 获取或者设置 Lastposter 属性.
///
/// </summary>
/// <value>类型是 nchar.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.String Lastposter
{
get { return _lastposter; }
set {
if (_lastposter == value)
{
return;
}
_lastposter = value; }
}
/// <summary>
/// 获取或者设置 Lastposterid 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Lastposterid
{
get { return _lastposterid; }
set {
if (_lastposterid == value)
{
return;
}
_lastposterid = value; }
}
/// <summary>
/// 获取或者设置 Views 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Views
{
get { return _views; }
set {
if (_views == value)
{
return;
}
_views = value; }
}
/// <summary>
/// 获取或者设置 Replies 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Replies
{
get { return _replies; }
set {
if (_replies == value)
{
return;
}
_replies = value; }
}
/// <summary>
/// 获取或者设置 Displayorder 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Displayorder
{
get { return _displayorder; }
set {
if (_displayorder == value)
{
return;
}
_displayorder = value; }
}
/// <summary>
/// 获取或者设置 Highlight 属性.
///
/// </summary>
/// <value>类型是 varchar.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.String Highlight
{
get { return _highlight; }
set {
if (_highlight == value)
{
return;
}
_highlight = value; }
}
/// <summary>
/// 获取或者设置 Digest 属性.
///
/// </summary>
/// <value>类型是 tinyint.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Byte Digest
{
get { return _digest; }
set {
if (_digest == value)
{
return;
}
_digest = value; }
}
/// <summary>
/// 获取或者设置 Rate 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Rate
{
get { return _rate; }
set {
if (_rate == value)
{
return;
}
_rate = value; }
}
/// <summary>
/// 获取或者设置 Hide 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Hide
{
get { return _hide; }
set {
if (_hide == value)
{
return;
}
_hide = value; }
}
/// <summary>
/// 获取或者设置 Poll 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Poll
{
get { return _poll; }
set {
if (_poll == value)
{
return;
}
_poll = value; }
}
/// <summary>
/// 获取或者设置 Attachment 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Attachment
{
get { return _attachment; }
set {
if (_attachment == value)
{
return;
}
_attachment = value; }
}
/// <summary>
/// 获取或者设置 Moderated 属性.
///
/// </summary>
/// <value>类型是 tinyint.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Byte Moderated
{
get { return _moderated; }
set {
if (_moderated == value)
{
return;
}
_moderated = value; }
}
/// <summary>
/// 获取或者设置 Closed 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Closed
{
get { return _closed; }
set {
if (_closed == value)
{
return;
}
_closed = value; }
}
/// <summary>
/// 获取或者设置 Magic 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Magic
{
get { return _magic; }
set {
if (_magic == value)
{
return;
}
_magic = value; }
}
/// <summary>
/// 获取或者设置 Identify 属性.
///
/// </summary>
/// <value>类型是 int.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Int32 Identify
{
get { return _identify; }
set {
if (_identify == value)
{
return;
}
_identify = value; }
}
/// <summary>
/// 获取或者设置 Special 属性.
///
/// </summary>
/// <value>类型是 tinyint.</value>
/// <remarks>
/// 该属性 不能设置为空
/// </remarks>
public System.Byte Special
{
get { return _special; }
set {
if (_special == value)
{
return;
}
_special = value; }
}
#endregion
#region 序列化和反序列化 静态方法
/// <summary>
/// 将对象序列化到文件
/// </summary>
/// <param name="path">需要保存的路径</param>
/// <returns>是否保存成功</returns>
public bool Serialize(string path)
{
return Serialize(path, this);
}
/// <summary>
/// 将对象序列化
/// </summary>
/// <param name="path">需要保存的路径</param>
/// <param name="objTopicsInfo">TopicsInfo对象</param>
/// <returns>是否序列化成功</returns>
public static bool Serialize(string path, TopicsInfo objTopicsInfo)
{
try
{
string dirName = System.IO.Path.GetDirectoryName(path);
if (!Directory.Exists(dirName))
{
Directory.CreateDirectory(dirName);
}
FileStream fs = new FileStream(path, FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, objTopicsInfo);
fs.Close();
fs.Dispose();
return true;
}
catch
{
return false;
}
}
2008-11-24 at 12:57