1 | ODataHttpRequestMessageExtensions.GetNextPageLink 和 |
要改用
1 | Request.ODataProperties().NextLink, |
ODataProperties 需要使用 System.Web.Http.OData.Extensions 或 System.Web.OData.Extensions 命名空間
1 | ODataHttpRequestMessageExtensions.GetNextPageLink 和 |
要改用
1 | Request.ODataProperties().NextLink, |
ODataProperties 需要使用 System.Web.Http.OData.Extensions 或 System.Web.OData.Extensions 命名空間
asp.net mvc webapi 2 提供了 IHttpActionResult 這個界面
這個界面的效果基本上是跟HttpResponseMessage是一樣的 但是在回傳值的表示有些微的不一樣,以下是整理表
IHttpActionResult | HttpResponseMessage Request.CreateResponse(HttpStatusCode) |
---|---|
Ok() | HttpStatusCode.OK |
InternalServerError() | HttpStatusCode.InternalServerError |
NotFound() | HttpStatusCode.NotFound |
more on http://msdn.microsoft.com/zh-tw/library/system.web.http.apicontroller_methods(v=vs.118).aspx
這樣子寫起來就乾淨很多了
javascript基本操作html5的 local storage方法
1 | // set item val |
如果要把array object存入到localstorage裡面,需要把object轉換成文字.所以可透過json的方法來處理
1 | JSON.stringify(object); |
ref:
使用OData時如果遇到model裡面有自訂欄位是資料庫不存在時,就會出現錯誤
解決方案請參閱此篇文章
OData 101: Using the [NotMapped] attribute to exclude Enum properties
當要同一時間新增大量資料時,如果單純用EF的新增方式,速度會讓人吐血。 所以需要透過BulkInsert的方式處理,但是又不想自己另外寫ado的方式處理,所以就要透過extenstion的方式, 讓EF的功能加強一下
##安裝 EntityFramework.BulkInsert-ef6
##參考文件
http://efbulkinsert.codeplex.com/
##(用法)Demo Code
1 | using(context db = new context()){ |
##執行結果 非常快速
如果利用Code first的方式,搭配DbMigration即可完成工作
1 | public class DemoContext : DbContext |
1 | using System; |
1 | using (var db = new AtaBookContext(connection1)){} |
connection1和connection2分別指到不同的資料庫,EF就會根據連線字串的設定產生相對應的資料庫
當要在htmlHelper裡面使用angularjs的屬性時, 原本的ng-model變成ng_model, 將 - 變成 _ 即可
例如:
1 | @Html.DropDownList("dropdown", (IEnumerable<SelectListItem>)ViewBag.items, new { ng_model = "currentSelect", ng_change = "selectChanges()" }) |
#NOTE: Youtube link: http://youtu.be/S8XL1L_1Lyw
1 | using System; |
1 | using System; |
1 | using System; |
part1
1 | using System; |
執行結果:
part2 (with using())
1 | using System; |
執行結果
part3 with Execute Around Method Pattern
1 | using System; |
執行結果
Ref from G+
Ater upgrading to AS 0.5.4 I am getting this error 「Failed to set up SDK Error:Module 『AndroinoTerm』: platform 『android-18』 not found」 while I already have android-18 installed. My sdk path is correctly setup and I am also able to run my project successfully. Does Anybody else having this issue ?
Solution: 1. Change sdk folder location 2. update sdk path in android studio 3. change back to original location 4. update sdk path setting in android studio again 5. problem solved
當網頁要讀取一個很大量的資料時,通常都會透過分頁的方式來顯示資料。 如果透過WebApi+OData的特性來做分頁,作法很單純 設定 WebApiConfig.cs
1 | //加入 |
假設原本的API寫法如下
1 | [Route("api/Customer")] |
改成
1 | [Route("api/Customer")] |
那在client端要呼叫api的url中,在加上OData的查詢語法來取得所要的資料區段,來達成分頁的效果
指令 | 說明 | 範例 |
---|---|---|
top | 結果挑出最前面的幾筆 | ?$top=3 |
skip | 略過幾筆。可用於分頁顯示 | ?$skip=10 |
orderby | 排序 | ?$orderby=SupplierID,ProductID |
filter | 篩選 | |
gt : > , 大於 | $filter=ProductID gt 10 | |
lt : < , 小於 | $filter=ProductID lt 10 | |
ge : >=, 大於等於 | $filter=ProductID ge 10 | |
le : <=, 小於等於 | $filter=ProductID le 10 | |
eq : =, 等於 | $filter=ProductID eq 10 | |
ne : <>, 不等於 | $filter=ProductID ne 10 |
參考資料: http://msdn.microsoft.com/en-us/library/windowsazure/gg312156.aspx
1 | [Route("api/Customer")] |
要傳入的東西是一樣的,但是回傳的結果會變成
1 | { |
所以在接收時要再調整
所送出的值前面要加上 guid 的關鍵字
1 | ?$filter=field eq guid'<value>' |