[attributeusage(attributetargets.property, allowmultiple = false, inherited = false)]/*用於給擴充套件類的屬性增加特性標識;如果實體類屬性有此標識,則不參與指令碼運算*/
public class i***tendfieldattribute:attribute
public class reputility//說明sys_是資料庫表名的字首;hashset是集合屬性;本例只支援單錶操作
order by ;";
/// /// p0:表名,p1:查詢條件,p2:排序欄位名,p3:排序方式,p4:第幾頁,p5:每頁顯示記錄數
///
public string pagesql = "select * from order by limit ,;";
/** mysql分頁:
select * from tablename where 條件 limit (當前頁碼-1)*頁面容量 , 頁面容量
*/#region 注意此方法不通用,可根據相應場景進行調整
/// /// 不通用,還在整理中;根據實體類物件生成查詢條件
///
///
///
///
public string getcondition(t instance) where t : class
else}}
}return builder.tostring();
}/// /// 根據實體類物件生成更新指令碼
///
///
///
/// 主鍵,這裡單獨把可以作為引數是為了更方便擴充套件
///
public string getupdatesql(t instance, string key) where t : class
else}}
}}
builder.remove(builder.length - 3, 3);//移除最有乙個逗號和換行符,\r\n佔兩位;"\r\n".length=2;
return builder.tostring();
}/// /// 根據實體類物件生成插入指令碼
///
///
///
///
///
public string getaddsql(t instance, string key) where t : class
else}}
//2.生成列
stringbuilder builder = new stringbuilder();
string tmp = string.empty;
foreach (var item in dict)
tmp = tmp.trimend(new char ) + ") values(";
//3.生成值
tmp = string.empty;
foreach (var item in dict)
tmp = tmp.trimend(new char ) + ");";
//4.返回
return builder.tostring();
}/// /// 拼接查詢指令碼
///
///
///
///
///
///
public string getsql(string orderby = "id", string sort = "asc", string where = " where 1=1 ") where t : class
#endregion
/// /// 拼接查詢數量的指令碼
///
///
///
///
public string getcountsql(string where = "where 1=1") where t : class
;", tbname, where);
return safesql;
}/// /// 拼接分頁的指令碼
///
///
///
///
///
///
///
///
public string getpagesql(string where = "where 1=1", string orderby = "id", string sort = "asc", int pagecurrentindex = 0, int pagesize = 10) where t : class
#region 可用列表
/// /// 根據引數生成查詢條件指令碼
///
/// list
///
public string getconditionwithparam(list> listpara, char flag = '?')
return builder.tostring();
}/// /// 根據實體類物件生成引數化的更新指令碼
///
///
///
///
///
///
///
public string getupdatesql(t instance, string key, ref list> listpara, char flag = '?') where t : class
else}}
}}
builder.remove(builder.length - 3, 1);//移除最有乙個逗號,\r\n佔兩位;"\r\n".length=2;
listpara.add(new tuple(key, "=", flag + key, objtype.getproperty(key).getvalue(instance)));
return builder.tostring();
}/// /// 根據實體類物件生成引數化的插入指令碼
///
///
///
///
///
///
///
public string getaddsql(t instance, string key, ref list> listpara, char flag = '?') where t : class
else}}
//2.生成列
stringbuilder builder = new stringbuilder();
string tmp = string.empty;
foreach (var item in dict)
tmp = tmp.trimend(new char ) + ") values(";
//3.生成值
tmp = string.empty;
foreach (var item in dict)
,", flag, item.key);
listpara.add(new tuple(item.key, "=", flag + item.key, item.value));
}tmp = tmp.trimend(new char ) + ");";
//4.返回
return builder.tostring();
}#endregion
}
xsd轉實體類
話說vs自帶的工具,可以將xsd或者xml格式的檔案轉成實體類,大概格式如下 使用vs2005工具xsd.exe sdk v2.0 bin xsd.exe 自動生成實體類 xsd c namespace mycompany language cs temp1.xsd 也可以生成dataset型別的類...
XML轉實體類工具
這裡使用到了jox依賴 com.wutka jox1.16 工具類 project gsj qcdzh company jit northeast r d description todo author dongwei date 2019年1月17日 上午9 47 33 version v1.0 p...
key,value集合轉實體類
在專案中碰到類似的情景,比較有意思,記錄一下 我手上有乙個集合,集合中有乙個實體類的欄位名稱和他的值,但是都是string型別的。需要將這個集合轉換為這個實體類。過程問題如下 1.我手上只有集合如何判定他是哪個實體類?2.集合中key和value都是string型別,如何轉換為對應的資料型別 3.如...