2015年12月22日 星期二

Nuget Re-target the framework

NuGet 2.1 offers a feature that makes this a lot simpler: just do 
update-package -reinstall -ignoreDependencies 
from the Package Manager Console.

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>