2013年10月24日 星期四

將 table 中多筆資料的某些欄位合併變成一個字串

select stuff((select  ',' + c1+c2 from table1 for xml path('')),1,1,'')

利用 for xml path('') 合併
利用 stuff('xxx',1,1,'') 去除第一個逗號

2013年10月22日 星期二

安裝 sql server express 2012 後卻找不到組態管理員 (windows 8)

To access SQL Server Configuration Manager Using Windows 8
Because SQL Server Configuration Manager is a snap-in for the Microsoft Management Console program and not a stand-alone program, SQL Server Configuration Manager not does not appear as an application when running Windows 8. To open SQL Server Configuration Manager, in the Search charm, under Apps, type SQLServerManager11.msc (for SQL Server 2012) or SQLServerManager10.msc for (SQL Server 2008), and then press Enter.

2013年10月9日 星期三

如何將父類別物件轉型成子類別物件

無法直接轉型,必須在父類別撰寫產生子類別物件的函數,範例如下
public virtual T Clone() where T : 調整單DisplayViewModel
        {
            var obj = (T)Activator.CreateInstance(typeof(T));
            obj.調整單號 = this.調整單號;
            obj.調整日期 = this.調整日期;
            obj.說明 = this.說明;
            obj.調整人員 = this.調整人員;
            obj.建檔人員 = this.建檔人員;
            obj.建檔時間 = this.建檔時間;
            return obj;
        }


使用範例
調整單ViewModel viewmodel = this.DisplayViewModel.Clone<調整單ViewModel>();

Entity Framework 建立新物件並儲存後馬上取得關聯資料

使用 CreateProxy 建立物件,不要直接 new var newmodel = _contextXXX.CreateProxy<yyy>(); ... _contextXXX.yyy.Add(newmodel); await _contextXXX.SaveC...