C#实体类模板
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace SNS_Entitys
{
public class SNSBlog
{
/// <summary>
/// 空实例化
/// </summary>
public SNSBlog(){}
/// <summary>
/// 使用DataRow实例化
/// </summary>
/// <param name="dr"></param>
public SNSBlog(DataRow dr)
{
SetBlog(dr);
}
/// <summary>
/// 设置博文数据
/// </summary>
/// <param name="dr"></param>
public void SetBlog(DataRow dr)
{
if (dr.Table.Columns.Contains("Id") && dr["Id"] != DBNull.Value && dr["Id"] != null)
Id = Convert.ToInt32(dr["Id"]);
if (dr.Table.Columns.Contains("Topic") && dr["Topic"] != DBNull.Value && dr["Topic"] != null)
Topic = dr["Topic"].ToString();
}
/// <summary>
/// 将类转化为SQL参数
/// </summary>
/// <returns>SQL参数数组</returns>
public SqlParameter[] ConvertToSqlParamenter()
{
SqlParameter[] parameters=new SqlParameter[]{
new SqlParameter("@Id",Id)
,new SqlParameter("@Topic",Topic)
};
return parameters;
}
#region 博文信息
private string topic = "";
/// <summary>
/// 话题
/// </summary>
public string Topic
{
get { return topic; }
set { topic = value; }
}
public long _id = 0;
/// <summary>
/// 博文编号
/// </summary>
public long Id
{
get { return _id; }
set { _id = value; }
}
#endregion
}
}