NHibernate中数据操作具体实例一例
NHibernate中数据操作具体实例一例
[Serializable()] public class WF_SYS_GRANT_s_ex : WF_SYS_GRANT_s, IWF_SYS_GRANT_s_ex { public bool ExitsOrgBymc(string gmc) { bool rbc = false; //string x = "select count(gmc) as rec_nums "; //x += " from WF_SYS_GRANT where gmc=‘" + gmc + "‘"; IList<WF_SYS_GRANT> t_list = null; if (this.dbsf != null) { using (ISession s = this.dbsf.OpenSession()) { t_list = s.QueryOver<WF_SYS_GRANT>() .Where(c => c.GMC == gmc) .List(); if (t_list != null && t_list.Count > 0) { rbc = true; } } } return rbc; } public WF_SYS_GRANT GetRecord(string gid) { //string x = "select * from WF_SYS_GRANT where gid=‘" + gid + "‘"; WF_SYS_GRANT tab = this.GetRecordByID(gid); return tab; } public bool DeleteRecordsByid(string gid) { bool rbc = false; //string x = ""; //x = "delete from WF_SYS_GRANT where gid=‘" + gid + "‘"; IList<WF_SYS_GRANT> t_list = null; if (this.dbsf != null) { using (ISession s = this.dbsf.OpenSession()) { t_list = s.QueryOver<WF_SYS_GRANT>() .Where(c => c.GID == gid) .List(); if (t_list != null && t_list.Count > 0) { this.DeleteList(t_list); } } } return rbc; } // public int GetRelationUserCount(string gid) { int rbc = 0; //string x = "select count(uid) as num_count from WF_SYS_USER_ROLE "; //x += " where rid in(select rid from WF_SYS_ROLE_GRANT where gid=‘" + gid + "‘)"; IList<WF_SYS_USER_ROLE> t_list = null; if (this.dbsf != null) { using (ISession s = this.dbsf.OpenSession()) { //子查询 QueryOver<WF_SYS_ROLE_GRANT> sub_query = QueryOver.Of<WF_SYS_ROLE_GRANT>() .Where(c => c.GID == gid) .Select(c => c.RID); //主查询 t_list = s.QueryOver<WF_SYS_USER_ROLE>() .WithSubquery .WhereProperty(x => x.RID) .In(sub_query) .List(); if (t_list != null && t_list.Count > 0) { rbc = t_list.Count(); } } } return rbc; } public int GetRelationRoleCount(string gid) { int rbc = 0; //string x = "select count(rid) as num_count from WF_SYS_ROLE_GRANT where gid=‘" + gid + "‘"; IList<WF_SYS_ROLE_GRANT> t_list = null; if (this.dbsf != null) { using (ISession s = this.dbsf.OpenSession()) { //主查询 t_list = s.QueryOver<WF_SYS_ROLE_GRANT>() .Where(c=>c.GID==gid) .List(); if (t_list != null && t_list.Count > 0) { rbc = t_list.Count(); } } } return rbc; } // }
[Serializable()] public class WF_SYS_GRANT_s : AbsDataMethod<Cwfapi.Model.WF_SYS_GRANT> { public WF_SYS_GRANT_s() { this._modelName = "系统权限表"; this.m_tableName = "WF_SYS_GRANT"; } public override IList<Cwfapi.Model.WF_SYS_GRANT> LoadALL() { using (ISession s = this.dbsf.OpenSession()) { IList<Cwfapi.Model.WF_SYS_GRANT> list = s.QueryOver<Cwfapi.Model.WF_SYS_GRANT>() .OrderBy(c => c.GID).Asc .List(); return list; } } public override IList<Cwfapi.Model.WF_SYS_GRANT> LoadList(object value) { using (ISession s = this.dbsf.OpenSession()) { IList<Cwfapi.Model.WF_SYS_GRANT> list = s.QueryOver<Cwfapi.Model.WF_SYS_GRANT>() .Where(c => c.GID == value) .OrderBy(c => c.GID).Asc .List(); return list; } } public override object GetKey(Cwfapi.Model.WF_SYS_GRANT entity) { return entity.GID; } }
[Serializable()] public class WF_SYS_GRANT:BaseDbTable { public virtual String GID { get; set; } public virtual String GMC { get; set; } public virtual String MS { get; set; } public virtual String EXTFD_1 { get; set; } public virtual String GTYPE { get; set; } public override object Clone() { WF_SYS_GRANT tab = new WF_SYS_GRANT(); tab.GID = this.GID; tab.GMC = this.GMC; tab.MS = this.MS; tab.EXTFD_1 = this.EXTFD_1; tab.GTYPE = this.GTYPE; return tab; } public override void CopyAttributeFromObject(object obj) { WF_SYS_GRANT t = obj as WF_SYS_GRANT; if (t != null) { this.GID = t.GID; this.GMC = t.GMC; this.MS = t.MS; this.EXTFD_1 = t.EXTFD_1; this.GTYPE = t.GTYPE; } } }
[Serializable()] public abstract class BaseDbTable : ILifecycle, IValidatable, ICopyAttributeFromObject, ICloneable { #region ILifecycle 成员 public virtual LifecycleVeto OnDelete(ISession s) { return LifecycleVeto.NoVeto; } public virtual void OnLoad(ISession s, object id) { } public virtual LifecycleVeto OnSave(ISession s) { return LifecycleVeto.NoVeto; } public virtual LifecycleVeto OnUpdate(ISession s) { return LifecycleVeto.NoVeto; } #endregion #region IValidatable 成员 public virtual void Validate() { if (1 != 1) { throw new ValidationFailure(); } } #endregion #region ICloneable 成员 public abstract object Clone(); #endregion #region ICopyAttributeFromObject 成员 public abstract void CopyAttributeFromObject(object obj); #endregion } public interface ICopyAttributeFromObject { void CopyAttributeFromObject(object obj); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。