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
t_list = null;
if (this.dbsf != null)
{
using (ISession s = this.dbsf.OpenSession())
{
t_list = s.QueryOver
() .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
t_list = null; if (this.dbsf != null) { using (ISession s = this.dbsf.OpenSession()) { t_list = s.QueryOver
() .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
t_list = null; if (this.dbsf != null) { using (ISession s = this.dbsf.OpenSession()) { //子查询 QueryOver
sub_query = QueryOver.Of
() .Where(c => c.GID == gid) .Select(c => c.RID); //主查询 t_list = s.QueryOver
() .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
t_list = null; if (this.dbsf != null) { using (ISession s = this.dbsf.OpenSession()) { //主查询 t_list = s.QueryOver
() .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
{
public WF_SYS_GRANT_s()
{
this._modelName = "
系统权限表";
this.m_tableName = "WF_SYS_GRANT";
}
public override IList
LoadALL() { using (ISession s = this.dbsf.OpenSession()) { IList
list = s.QueryOver
() .OrderBy(c => c.GID).Asc .List(); return list; } } public override IList
LoadList(object value) { using (ISession s = this.dbsf.OpenSession()) { IList
list = s.QueryOver
() .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
{
#reg