关于ClownFish的问题
1.下面是我获取实体集合的方法 ,
public IList<Model.Employee> GetList(int pageindex, string name, out int recCount) { var parameters = new { EmpName = name, PageIndex = 1, PageSize = 15, TotalRecords = 0 }; string sql = @" ;WITH MyList AS ( SELECT row_number() OVER ( ORDER BY p.AddDate ASC ) AS rownumber ,p.* FROM dbo.[Employee] p WHERE len(@EmpName)=0 or p.EmpName like '%'+ @EmpName +'%' ) SELECT rownumber , * FROM MyList WHERE rownumber >= ( @pageindex - 1 ) * @pagesize + 1 AND rownumber <= ( @pageindex - 1 ) * @pagesize + ( @pagesize ); select @TotalRecords=count(*) FROM dbo.[Employee] p WHERE len(@EmpName)=0 or p.EmpName like '%'+ @EmpName +'%' "; using (DbContext dbContext = new DbContext(false)) { dbContext.CreateCommand(sql, CommandType.Text); dbContext.SetCommandParameters(parameters); dbContext.AddParameter("TotalRecords", 0, DbType.Int32, 4, ParameterDirection.Output); List<Model.Employee> list = dbContext.FillList<Model.Employee>(); recCount = parameters.TotalRecords; return list; } }
结果发生了这个异常 , 不知为何?
2.下面这个是我的实体:
public class Employee { public Employee() { } private Int32 _EmpId; /// <summary> /// 用户ID /// </summary> public Int32 EmpId { get { return _EmpId; } set { _EmpId = value; } } ........... private string _EmpName; /// <summary> /// 用户名称 /// </summary> public string EmpName { get { return _EmpName; } set { _EmpName = value; } } private DateTime? _Birthday; /// <summary> /// 生日 /// </summary> public DateTime? Birthday { get { return _Birthday; } set { _Birthday = value; } } private DateTime _AddDate; /// <summary> /// 录入时间 /// </summary> public DateTime AddDate { get { return _AddDate; } set { _AddDate = value; } } }
下面是我新增Employee的方法
public override int Add(Model.Employee model) { string sql = @" insert into [Employee] ([LoginId],[EmpName],[EmpPwd],[IdNumber],[Telephone],[Fixphone],[Birthday],[Sex],[JobName],[EmpState],[DistName],[OrderQuota],[ShipQuota],[JoinDate],[BizType],[Roles]) values (@LoginId,@EmpName,@EmpPwd,@IdNumber,@Telephone,@Fixphone,@Birthday,@Sex,@JobName,@EmpState,@DistName,@OrderQuota,@ShipQuota,@JoinDate,@BizType,''); select scope_identity();"; using (DbContext dbContext = new DbContext(true)) { model.EmpId = DbHelper.ExecuteScalar<int>(sql, model, dbContext, CommandKind.SqlTextWithParams); dbContext.CommitTransaction(); } return model.EmpId; }
Birthday此时是null值, 即该员工未填写生日 , 执行Add方法时结果出现以下错误:
以下是SqlProfiler捕获的信息:
大家知道是什么问题吗??
来自杭州西溪。主打Linux系统架构、维优、项目外包