1
我正在嘗試生成一些自定義實體和自定義方法以從數據庫中獲取數據。檢測表的主鍵
ListByPrimaryKey
- 列名,有時是 「ID」, 「PID」, 「ID」 等
你怎麼能檢測到一列是使用C#,使用T4模板的主鍵?
protected void GenerateListByMethods(Table table)
{
WriteLine("#region ListBy\n");
WriteLine("\n\tpublic List<"+Prefix+table.Name+"> ListAll()\n\t{\n\t " +
this.RepositoryNotification +
"\n\t\t\t return Ctx.GetAll().ToList().ToCustomList<"+table.Name+","+Prefix+table.Name+">();\n\t}\n");
foreach (Column column in table.Columns)
{
switch(column.DataType.Name)
{ // do something
如何編寫column.DataType.IsPrimaryKey
的擴展方法?
其中'ORM'您使用的?看看[這個](http://stackoverflow.com/a/8801227/601179)'NHibernate'的答案 – gdoron
你有沒有想過只運行一個數據庫查詢..? – MethodMan