2015年10月2日 星期五

Ajax Manager


今天寫程式時發現 Telerik AjaxManager 不能正常運作 (對應的 ajax setting 設定好後, 元件呼叫 auto postback 後, 竟然會重新換頁)

後來發現是 Ajax Manager 得出線順序有影像, 後來動手調整順序後, AjaxManager 才正確運作, 心得: 不要將 Ajax Manager 放到比 RadScriptManager 前.





2015年8月29日 星期六

EF 6 (Single and Bulk Update)

EF Extesnion loresoft

Bulk Update  (Directly delete and auto commit)
db.People.Where(it => it.DeptId =="101").Update(it => new People { Salary = it.Salary * 1.1 });

Bulk Delete (Directly delete and auto commit)
ex:
db.People.Where(it => it.DepId =="101").Delete();  // where db the the DbContext

EF update without select (Single Update)

var newPeople = new People { PeopleId = "0001" };  // where PeopleId is the key 
db.People.Attach(newPeople);
newPeople.{attribute1} = {new value1};  // assume there are 8 attributes in People object
newPeople.{attribute4} = {new value4};
newPeople.{attribute6} = {new value6};
db.SaveChanges();

after db.SaveChages(); sql will be generated like this update people  set attribute1 = newValue1, attribute4 = newValue4, attribute6 = newValue6 where PeopleId = '0001';  
system only update the changed items 

in another case (ref to this article https://msdn.microsoft.com/en-us/data/jj592676.aspx)
var newPeople = new People { PeopleId = "0001" };   // where PeopleId is the key 
db.Entry(newPoeple).State = EntityState.Modified;
newPeople.{attribute1} = {new value1};  // assume there are 8 attributes in People object
newPeople.{attribute4} = {new value4};
newPeople.{attribute6} = {new value6};
db.SaveChanges();

When you change the state to Modified all the properties of the entity will be marked as modified and all the property values will be sent to the database when SaveChanges is called. That means all attibutes in this entity will be populated to the database and the null value will be the default if you do not specify in above codes.

EF delete without select (Single Delete)
var newPeople = new People { PeopleId = "0001" };  // where PeopleId is the key 
db.Entry(newPoeple).State = EntityState.Deleted;
db.SaveChanges();
or

db.Entry(new People { PeopleId = "0001"} ).State = EntityState.Deleted;
db.SaveChanges();

2015年8月27日 星期四

Table 更新需要對應的跟新的 VIEW (sp_refreshview)

After creating a view, the meta data of the view will be stored and will not change even the table that relies is changed.

There are many ways to solve the problem. The first one is drop the view and create the view. Power Designer is good at that. This tool will generate the complete script to do that. However there is anther stored procedure to support this. it is sp_refreshview.

command example:
sp_refreshview v_name


In the mean time, we could run the following script to retrieve all the views that should be rerun sp_refreshview once the table is changed:


SELECT DISTINCT 'EXEC sp_refreshview ''' + name + ''''
FROM sys.objects so INNER JOIN sys.sql_dependencies sd
ON so.object_id = sd.object_id
WHERE type = 'V'
AND sd.referenced_major_id = object_id('TABLE_WHO_IS_CHANGED');

2015年8月18日 星期二

EF 6 + .NET 4 遇到資料載入錯誤的畫面

EF 6.1.3 + .NET Framework 4
若系統只有 .net 4 系統要執行 Telerik RadGrid 載入資料時, 系統將會出現類似下面的錯誤
Duranet2Model.csdl(2,9) : warning 0005: Could not find schema information for the attribute 'Namespace'.
Duranet2Model.csdl(2,35) : warning 0005: Could not find schema information for the attribute 'Alias'.
Duranet2Model.csdl(2,48) : error 0005: The 'http://schemas.microsoft.com/ado/2009/02/edm/annotation:UseStrongSpatialTypes' attribute is not declared.
Duranet2Model.csdl(2,2) : error 0010: The element Schema in namespace http://schemas.microsoft.com/ado/2009/11/edm was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm, http://schemas.microsoft.com/ado/2007/05/edm, http://schemas.microsoft.com/ado/2008/09/edm.

解決方式

安裝 .NET Framework 4.5.x 就可以解決

2015年2月28日 星期六

C# Linq/ EF 如何利用一句 Syntax 完成多個 Aggregate

var x = (from item in SHIPMENTs group item by item.SOLD_TO)
.Select(it=> new {A = it.Sum( g=>g.DELIVER_QTY) , 
                             B = it.Sum(g=>g.AMOUNT)
                            }
);

2015年2月15日 星期日

Telerik Grid Width

1. By default, Grid will use auto layout for grid
2. If we need to specify the width

  set TableLayout="Fixed" and specified the column header and item to a specified width

Ex:

 <MasterTableView DataKeyNames="DELL_ACTIVITY_SHIPMENT_ID" 
                        DataSourceID="EntityDataSource1" ShowGroupFooter="true" TableLayout="Fixed">
                        <Columns>
                            <telerik:GridBoundColumn DataField="ROW_NO" 
                                HeaderText="ROW NO" AllowFiltering="false" 
                                SortExpression="ROW_NO" UniqueName="ROW_NO" DataType="System.Int32">
                                <HeaderStyle Width="60px" />

                                <ItemStyle Width="60px" />
 </telerik:GridBoundColumn>

2014年9月21日 星期日

管住自己嘴的21戒!

網路上看到的,自我反省

1、戒多言:說話不要太多,言多必失。
2、戒輕言:不要輕率地講話,輕言的人會召來責怪和羞辱。
3、戒狂言:不要不知輕重,胡侃亂說。胡侃亂說,往往後悔。
4、戒雜言:說話不可雜亂無章。雜亂無章,就會言不及義,傷害自己的美德。
5、戒戲言:不要不顧分寸地開玩笑,否則會引起沖突,招來禍害。
6、戒直言:不要不顧後果地直言不諱,否則也會引起麻煩。
7、戒盡言:說話要含蓄,不要不留有余地。
8、戒漏言:不要泄露機密。事以密成,語以漏敗。
9、戒惡言:不說無禮中傷的話,不要惡語傷人。(刀瘡易沒,惡語難消.)
10、戒巧言:不要花言巧語。花言巧語的人,必然虛偽。
11、戒矜言:不要驕傲自滿,自以為是。自矜自誇,是涵養不夠的表現。
12、戒讒言:不要背後說別人的壞話。背後說人壞話,會弄得天下都不太平。
13、戒訐言:不要攻人短處,揭人瘡疤。揭人瘡疤的人,招人痛恨,害人害己。

14、戒輕諾之言:不要輕易向人許願。輕易許願,會喪失信用。
15、戒強聒之言:不要嘮嘮刀刀,別人不願聽也說個不停,使人厭煩。
16、戒譏評之言:不要說譏諷別人的話。喜歡譏諷議論別人的人,對自己的要求往往馬虎。
17、戒出位之言:不要說不符合自己身份、地位的話。
18、戒狎下之言:不要對下屬講過份親密的話,以免下屬迎合妳而落入圈套。
19、戒諂諛之言:不要說吹捧奉承別人的話。吹捧奉承別人,是人品卑微的表現。
20、戒卑屈之言:不要低三下四,說奴言婢膝的話,因為德厚者無卑詞。
21、戒取怨之言:不要說招人怨恨的話,播下使人怨恨的種子。