using System;
using System.Data;namespace Models
{
/// <summary>
/// 用户类
/// </summary>
[Serializable]
public partial class Users
{
public Users() { }
public Users(int id, string userName, string userPassword, int? isAdmin, int? isLock)
{
this.ID = id;
this.UserName = userName;
this.UserPassword = userPassword;
this.IsAdmin = isAdmin;
this.IsLock = isLock;
}
public Users(IDataReader reader)
{
if (ModelHelper.HasColumn(reader, "ID"))
{
if (reader["ID"] != DBNull.Value)
{
this.ID = (int)reader["ID"];
}
}
if (ModelHelper.HasColumn(reader, "UserName"))
{
if (reader["UserName"] != DBNull.Value)
{
this.UserName = (string)reader["UserName"];
}
}
if (ModelHelper.HasColumn(reader, "UserPassword"))
{
if (reader["UserPassword"] != DBNull.Value)
{
this.UserPassword = (string)reader["UserPassword"];
}
}
if (ModelHelper.HasColumn(reader, "IsAdmin"))
{
if (reader["IsAdmin"] != DBNull.Value)
{
this.IsAdmin = (int?)reader["IsAdmin"];
}
}
if (ModelHelper.HasColumn(reader, "IsLock"))
{
if (reader["IsLock"] != DBNull.Value)
{
this.IsLock = (int?)reader["IsLock"];
}
}
}
public int? ID{get;set;}
/// <summary>
/// 用户名
/// </summary>
public string UserName{get;set;}
/// <summary>
/// 密码
/// </summary>
public string UserPassword{get;set;}
/// <summary>
/// 是否管理员 0否 1是
/// </summary>
public int? IsAdmin{get;set;}
/// <summary>
/// 是否启用 0否 1是
/// </summary>
public int? IsLock{get;set;}
}
}C#类
using System.Data;namespace Models
{
/// <summary>
/// 用户类
/// </summary>
[Serializable]
public partial class Users
{
public Users() { }
public Users(int id, string userName, string userPassword, int? isAdmin, int? isLock)
{
this.ID = id;
this.UserName = userName;
this.UserPassword = userPassword;
this.IsAdmin = isAdmin;
this.IsLock = isLock;
}
public Users(IDataReader reader)
{
if (ModelHelper.HasColumn(reader, "ID"))
{
if (reader["ID"] != DBNull.Value)
{
this.ID = (int)reader["ID"];
}
}
if (ModelHelper.HasColumn(reader, "UserName"))
{
if (reader["UserName"] != DBNull.Value)
{
this.UserName = (string)reader["UserName"];
}
}
if (ModelHelper.HasColumn(reader, "UserPassword"))
{
if (reader["UserPassword"] != DBNull.Value)
{
this.UserPassword = (string)reader["UserPassword"];
}
}
if (ModelHelper.HasColumn(reader, "IsAdmin"))
{
if (reader["IsAdmin"] != DBNull.Value)
{
this.IsAdmin = (int?)reader["IsAdmin"];
}
}
if (ModelHelper.HasColumn(reader, "IsLock"))
{
if (reader["IsLock"] != DBNull.Value)
{
this.IsLock = (int?)reader["IsLock"];
}
}
}
public int? ID{get;set;}
/// <summary>
/// 用户名
/// </summary>
public string UserName{get;set;}
/// <summary>
/// 密码
/// </summary>
public string UserPassword{get;set;}
/// <summary>
/// 是否管理员 0否 1是
/// </summary>
public int? IsAdmin{get;set;}
/// <summary>
/// 是否启用 0否 1是
/// </summary>
public int? IsLock{get;set;}
}
}C#类
解决方案 »
- page_load 中动态添加的控件为什么提交后得不到对象阿??
- 能不能在td的onclick中把session变量设为null
- [资源共享]再次开放注册,免费ASP.NET虚拟主机服务!
- js中如何设置dropdownlist Web控件中的selectedIndex属性?
- Asp.net(C#)使用OleDb向Oracle存图片问题
- dropdownlist的棘手问题
- 如何实现动态根据分类读出所属分类的新闻!
- 导入excel文档时的操作
- ASP.NET可以调用.NET Remoting远程对象吗?
- 如何判断一个字符串中是否含有某一字符?
- vs2010安装ajax
- 为什么点击按钮后,页面无法跳转?
using (var conn = new OracleConnection(cnStr))
{
conn.Open();
var comm = conn.CreateCommand();
comm.CommandText = "select e.id, e.name,e.ps,e.lck from Users as e where ..........";
comm.CommandType = System.Data.CommandType.Text;
result = ( from DbDataRecord record in comm.ExecuteReader()
let name = (string)record["TheName"]
select new User{
Name = name,
ID = (string)record["ID"],
Password = (string) record["ps"],
IsLock=(bool)record["lck"]
};
).ToList();
}
这样的语句直截了当地使用 IDataReader 接口。但是Model层代码是贯穿UI、BLL、DAL的代码,它的设计应该是比较简单干净的,例如就是namespace Models
{
/// <summary>
/// 用户类
/// </summary>
[Serializable]
public partial class User
{
public int ID{get;set;}
public string Name{get;set;}
public string Password{get;set;}
public bool IsAdmin{get;set;}
public bool IsLock{get;set;}
}而不应该依赖于 ADO.NET 这样的 DAL 类库。最后算是小语法了,不是什么大事。在数据库表设计中不要动不动就设置字段为允许null值。在这个前提下,少数确实是null值跟默认值有意义需要区分的字段,在读取时区分一下就行了,例如Password = record["ps"]==null? null: (string) record["ps"],