C# 實體類產生工具

來源:互聯網
上載者:User

我知道:這類工具在網上已有不少。但下載後一試用,很是不爽!
               要麼過於龐大,使用起來比較複雜,似乎殺雞焉用牛刀;
               要麼太過簡單,使用起來難以滿足我的需求。

而此工具要做到既小巧,又實用,可謂之“眾裡尋他千百度,擺渡百度無覓處” ^_^

No way out, do it yourself !  so,  有了下文 。。。

根據實際需求,站在使用者角度,編寫了此工具。
本人之此工具,不可謂之很有技術含量,但一定小巧實用;
本人之此工具,不可謂之多麼強大完美,但一定體貼入微;

實現功能:
1、能自動獲得使用者資料庫中的所有資料表;
2、能根據使用者所選的資料表,自動產生實體類;
3、能根據使用者的需求和選擇,動態產生建構函式;
4、文本顯示實現了關鍵字彩色區分;
5、能一鍵複製到剪下板中,供使用者拷貝;
6、能自動產生 C# 實體類的(*.cs)代碼檔案;

 

介面:

 

 

SQL語句參考代碼:

SQL代碼

use master
go

-- 查看 DBMS 中所有對象
select * from sysobjects

-- 查看 DBMS 中所有資料庫
select * from sysdatabases

------------------------------------------------------
use yourDataBase
go

-- 查看"yourDataBase"資料庫中所有的表
select * from yourDataBase.information_schema.tables

-- 查看"yourDataBase"資料庫中所有的欄位
select * from yourDataBase.information_schema.columns 

-- 查看"yourDataBase"資料庫中,"yourTable"表的相關欄位的屬性
select column_name,data_type --資料類型
  from yourDataBase.information_schema.columns 
  where table_name='yourTable'

select column_name,is_nullable --是否為空白
  from yourDataBase.information_schema.columns 
  where table_name='yourTable'

C#語句參考代碼:

C#代碼


// 1 提供將資料置於系統剪貼簿中以及從中檢索資料的方法。
Clipboard.SetDataObject(richTextBox1.Text);

// 2 讓瀏覽器開啟超連結位址
private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
{
    System.Diagnostics.Process.Start(e.LinkText);
    // 或 System.Diagnostics.Process.Start("IExplore.exe", e.LinkText);
}

// 3 改變關鍵字的顏色
private void changeColor(string keyword) // keyword 關鍵字
{
    int n_bool = 0;
    int start = 0;
    while (n_bool != -1)
    {
        n_bool = txtEntityClass.Find(keyword, start,
                          RichTextBoxFinds.WholeWord | RichTextBoxFinds.MatchCase);
        start = (n_bool == 1) ? start + keyword.Length : start + 1;
        txtEntityClass.SelectionColor = Color.Blue;
    }
}

// 4 可以考慮將 RichTextBox 控制項替換為 WebBrowser 控制項;

實體類產生工具[下載]

補記:

1. 對資料庫中少用的資料類型,在C#語言中補充了相互關聯類型的映射;
2. 修複了C#產生欄位的順序沒按照資料庫表中欄位的順序的BUG;

    感謝“永遠的阿哲”所提供的反饋!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.