Thursday, October 29, 2015

Một số lưu ý khi sử dụng Json.NET

1. Create Json Model Object: sử dụng JsonProperty để định nghĩa tên của 1 field.


2. Khi parse json string. Nên parse thành JToken, vì nó tổng quan nhất, sau đó dựa vào cái type của nó để xác định xem nên parse thành gì (nếu không có thể sẽ bị exception). Điều này quan trọng để parse string thành 1 type nào đó, đôi lúc string không hợp lệ cho type đó.

Tuesday, October 20, 2015

How to detect error base on RestSharp returned response fields?



Never check ErrorMessage for detecting error, just check StatusCode.


Note. This picture is In case of using Asp Web Api 2, doesn't has ErrorMessage but has System.Net.HttpStatusCode.NotFound status. (See all http status codes)

Một số lưu ý khi sử dụng SQLite

Links hay:
  http://blogs.msdn.com/b/matt/archive/2008/05/22/into-to-linq-to-sql-optimistic-concurrency.aspx

1. Khi tạo các model, sử dụng namespace using System.Data.Linq.Mapping;
Example:
[Table(Name = "McmUser")]
    public class McmUser
    {
        [Column(Name = "Username", IsPrimaryKey = true)]
        public string Username { get; set; }

        [Column(Name = "IsActive")]
        public bool IsActive { get; set; }
    }

2. Không sử dụng 1 số hàm sau trên IQueryable (của System.Linq):

  1. First
  2. FirstOrDefault
  3. ElementAt
3. Sử dụng Lock trên 1 DataContext See