新聞中心
下面看一個例子:

成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、東源網(wǎng)絡(luò)推廣、成都小程序開發(fā)、東源網(wǎng)絡(luò)營銷、東源企業(yè)策劃、東源品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供東源建站搭建服務(wù),24小時服務(wù)熱線:18980820575,官方網(wǎng)址:www.cdcxhl.com
現(xiàn)在有一個用戶信息的表:E-R圖如下:
要實(shí)現(xiàn)該表的數(shù)據(jù)庫新增、修改、查詢功能,需要實(shí)現(xiàn)下面兩個業(yè)務(wù)類:
- using Csla;
- using IF.CslaCore;
- using IF.OrmCore.DataSchema;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace IF.SysUser.Business
- {
- [Serializable]
- [TableClass(FriendlyName="用戶信息表",TableName="SYS_USER")]
- public class SysUser : IfBusiness
- {
- private static readonly PropertyInfo
SUR_IDProperty = RegisterProperty (c => c.SUR_ID); - [DisplayName("SUR_ID")]
- [FieldDescription(IsPrimaryKey=true,ColumnName="SUR_ID",FriendlyName="SUR_ID",NeedUpdate=true)]
- public string SUR_ID { get; set; }
- private static readonly PropertyInfo
UserNameProperty = RegisterProperty (c => c.UserName); - [DisplayName("登錄名")]
- [FieldDescription(ColumnName="SUR_USERNAME",FriendlyName="登錄名",NeedUpdate=true)]
- public string UserName { get; set; }
- private static readonly PropertyInfo
NameProperty = RegisterProperty (c => c.Name); - [DisplayName("姓名")]
- [FieldDescription(ColumnName="SUR_NAME",FriendlyName="姓名",NeedUpdate=true)]
- public string Name { get; set; }
- private static readonly PropertyInfo
PasswordProperty = RegisterProperty (c => c.Password); - [DisplayName("密碼")]
- [FieldDescription(ColumnName="SUR_PASSWORD",FriendlyName="密碼",NeedUpdate=true)]
- public string Password { get; set; }
- private static readonly PropertyInfo
LoginMacProperty = RegisterProperty (c => c.LoginMac); - [DisplayName("登錄Mac地址")]
- [FieldDescription(ColumnName="SUR_LOGIN_MAC",FriendlyName="登錄Mac地址",NeedUpdate=true)]
- public string LoginMac { get; set; }
- private static readonly PropertyInfo
LoginIPProperty = RegisterProperty (c => c.LoginIP); - [DisplayName("登錄IP")]
- [FieldDescription(ColumnName="SUR_LOGIN_IP",FriendlyName="登錄IP",NeedUpdate=true)]
- public string LoginIP { get; set; }
- private static readonly PropertyInfo
LoginTimeProperty = RegisterProperty (c => c.LoginTime); - [DisplayName("登錄時間")]
- [FieldDescription(ColumnName="SUR_LOGIN_TIME",FriendlyName="登錄時間",NeedUpdate=true)]
- public DateTime? LoginTime { get; set; }
- private static readonly PropertyInfo
LogoutTimeProperty = RegisterProperty (c => c.LogoutTime); - [DisplayName("登出時間")]
- [FieldDescription(ColumnName="SUR_LOGOUT_TIME",FriendlyName="登出時間",NeedUpdate=true)]
- public DateTime? LogoutTime { get; set; }
- private static readonly PropertyInfo
LoginFailTimeProperty = RegisterProperty (c => c.LoginFailTime); - [DisplayName("登錄失敗時間")]
- [FieldDescription(ColumnName="SUR_LOGIN_FAIL_TIME",FriendlyName="登錄失敗時間",NeedUpdate=true)]
- public DateTime? LoginFailTime { get; set; }
- private static readonly PropertyInfo
LoginFailCountProperty = RegisterProperty (c => c.LoginFailCount); - [DisplayName("登錄失敗次數(shù)")]
- [FieldDescription(ColumnName="SUR_LOGIN_FAIL_COUNT",FriendlyName="登錄失敗次數(shù)",NeedUpdate=true)]
- public Int32? LoginFailCount { get; set; }
- private static readonly PropertyInfo
LockFGProperty = RegisterProperty (c => c.LockFG); - [DisplayName("是否鎖定")]
- [FieldDescription(ColumnName="SUR_LOCK_FG",FriendlyName="是否鎖定",NeedUpdate=true)]
- public bool? LockFG { get; set; }
- private static readonly PropertyInfo
DisableFGProperty = RegisterProperty (c => c.DisableFG); - [DisplayName("是否有效")]
- [FieldDescription(ColumnName="SUR_DISABLE_FG",FriendlyName="是否有效",NeedUpdate=true)]
- public bool? DisableFG { get; set; }
- #region 通用字段
- private static readonly PropertyInfo
CreateTimeProperty = RegisterProperty (c => c.CreateTime); - [DisplayName("創(chuàng)建時間")]
- [FieldDescription(ColumnName="CreateTime",FriendlyName="創(chuàng)建時間",NeedUpdate=true)]
- public override DateTime? CreateTime { get; set; }
- private static readonly PropertyInfo
LastUpdateTimeProperty = RegisterProperty (c => c.LastUpdateTime); - [DisplayName("***修改時間")]
- [FieldDescription(ColumnName="LastUpdateTime",FriendlyName="***修改時間",NeedUpdate=true)]
- public override DateTime? LastUpdateTime { get; set; }
- public override void SetPrimaryKey(string key)
- {
- SUR_ID = key;
- }
- #endregion
- }
- [Serializable]
- public class SysUserList : IfBusinessList
- { }
- }
現(xiàn)在就可以工作了:
全表檢索數(shù)據(jù)方法:
- SysUserList selData = SysUserList.Fetch();
向數(shù)據(jù)庫新增一條數(shù)據(jù):
- SysUser.Business.SysUser user = new SysUser.Business.SysUser();
- user.UserName= "inaction";
- user.Name = "流砂";
- user.Password= "superman";
- selData.Add(user);
- selData.Save();
向數(shù)據(jù)庫修改數(shù)據(jù):
- var user = SysUserList.Fetch(c => c.UserName == "inaction");
- user.Password = "123456";
- SysUserList list = new SysUserList { user };
- list.Save();
以上代碼就實(shí)現(xiàn)了對密碼的修改。
特別說明:目前IF 只能通過SysUserList對象的Save方法保存數(shù)據(jù)。以后會實(shí)現(xiàn)通過業(yè)務(wù)類自身Save方法保存數(shù)據(jù)。
新聞標(biāo)題:自己寫數(shù)據(jù)庫訪問ORM
本文URL:http://m.fisionsoft.com.cn/article/cdjdhpo.html


咨詢
建站咨詢
