2014年12月5日 星期五

[第一章] 用Mono Develop直接開發C#程式(安裝流程)


按crtl+alt+t 啓動終端機

執行:

1.
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

2.
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list

3.
apt-get install MonoDevelop

4.
安裝完成後再usr/share/applications中找到MonoDevelop


可以看到我的界面預設是簡體字














5.
在編輯>preferences將語言設為tw















6.
終端機中執行apt-get install monodevelop-database 安裝資料庫外掛工具到Mono Develop


在Mono Develop選單中的工具就出現database連接工具囉




更多內容請參考:

Install MonoDevelop on Linux


Mono Develop各作業系統版本下載:

http://www.monodevelop.com/download


2014年12月4日 星期四

[Code First] custom Initializer


建立一個類別繼承  DbContext










在web.config中指定你的連線字串[各版本的連線字串寫法]






1.自訂你的 Initializer 並選擇什麼情況下重建你的資料庫

CreateDatabaseIfNotExists (資料庫不存在時重建)


DropCreateDatabaseWhenModelChanges (改變你的模型時重建)


DropCreateDatabaseAlways (每次都重新建立)


2.覆寫Seed方法,建立資料庫的初始資料














在web.config中加入<context>記錄,指定你的context和 Initializer









更多內容可以參考此篇:

Understanding Database Initializers in Entity Framework Code First




2014年12月1日 星期一

Vistual Studio 2013開發工具與路徑


2013開發人員命令列工具:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts\

執行Developer Command Prompt for VS2013.exe(英文版)













IIS Express 站台設定檔位置:

C:\Users\USER\Documents\IISExpress\config








IIS Express 命令列位置:

C:\Program Files\IIS Express

appcmd.exe list site 列出站台

appcmd.exe  site /? 站台可執行命令

iisexpress.exe /site:1 啓動IIS Express 站台1

更多內容可以參考:

http://www.iis.net/learn/extensions/using-iis-express/running-iis-express-from-the-command-line


開啓IIS Express站台供外部連結:(失敗)

用筆記本開啓 C:\Users\USER\Documents\IISExpress\config\applicationhost.config

將localhost 已為*










最後再新增保留區

netsh http add urlacl url=http://*:(埠號)/ user=everyone


20141130:在window8上測試失敗,使用IP方式出現503錯誤,localhost則正常







2014年11月24日 星期一

Coding First Data Annotations (Model屬性的相關標註說明)

假設有一個Model的類別
    public class User {
        public int Id { get; set; }
        public string PersonalId { get; set; }
        public string Name { get; set; }
    }

[Key]:索引鍵
        [Key]
        public int Id { get; set; }

[Key,Column(Oerder=n)]複合索引鍵:
        [Key]
        [Column(Order=1)]
        public string PersonalId { get; set; }
        [Key]
        [Column(Order=2)]
        public string Name {get;set;}

[Required]:必要欄位不可為空

        [Required]
        public int Id { get; set; }

[MaxLength(n),ErrorMessage=”your message“,MinLength(n)]:最大和最小值和自訂錯誤訊息
        [MaxLength(2),ErrorMessage=”姓名欄位請輸入2~5個字“,MinLength(5)]
        public string Name { get; set; }   

[NotMapped]:不須建立資料庫的欄位
        [NotMapped]
        string sex = PersonalId.Substring(1, 1)=="1"?"男":"女"; 

[Table][Column]:自訂資料庫表格和欄位名稱
        [Table("MyUser")]
        public class UserModel{
            [Column("Myid",TypeName="ntext")]
            string PersonalId{get;set;}
       }

[Index]:欄位建立搜尋索引EF6.1以後版本才有此功能,預設的索引名稱是IX_
        [Index("MyIndexName")]
        public string Name {get;set;}
       }



需要參考以下兩個組件:
using System.ComponentModel.DataAnnotations; 
using System.ComponentModel.DataAnnotations.Schema; 


2014年11月23日 星期日

各版本的Sql connection 字串寫法

LocalDB:
<add name="ConnectionStringName" providerName="System.Data.SqlClient"  
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFileName=|DataDirectory|\DatabaseFileName.mdf;InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True" />

Sql Express:
<add name="ConnectionStringName" providerName="System.Data.SqlClient"
    connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True"/>
Sql Server:
<add name="ConnectionStringName" providerName="System.Data.SqlClient"
    connectionString="Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=False;User Id=userid;Password=password;MultipleActiveResultSets=True" />                        

SQL Azure:
<add name="ConnectionStringName"  providerName="System.Data.SqlClient"
    connectionString="Data Source=tcp:ServerName.database.windows.net,1433;Initial Catalog=DatabaseName;Integrated Security=False;User Id=username@servername;Password=password;Encrypt=True;TrustServerCertificate=False;MultipleActiveResultSets=True" />

Entity Framework Database:
<add name="ConnectionStringName"  providerName="System.Data.EntityClient"
    connectionString="metadata=res://*/ ContextClass.csdl|res://*/ ContextClass.ssdl|res://*/ ContextClass.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=ServerName;Integrated Security=False;User Id=userid;Password=password;MultipleActiveResultSets=True&quot;" />

Sql Compact:
<add name="ConnectionStringName" providerName="System.Data.SqlServerCe.4.0"
    connectionString="Data Source=|DataDirectory|\DatabaseFileName.sdf" />

2014年11月20日 星期四

Adjacent selectors的用法,li中的範例


<style  type="text/css">
li{
color: maroon;
}
li+li{
color: silver;
}
li+li+li{
color: blue;
}
</style>


<body>

<ol>
<li>第1個重點</li>
<li>第2個不太重要</li>
<li>第3個太不重要了</li>
</ol>

</body>


結果:



2014年11月19日 星期三

child selector 與 descendant selector的差異性

<style  type="text/css">
div{
font-size:x-large;
background-color:black;
}

//descendant selector 後代
div  span{
background:red;
}

//child selector 孩子
div > span{
background:blue;
}

</style>

<body>
<div><span>123</span><span>456<span>789</span></span></div>
</body>



結果:





熱門文章