webapi相关知识

1、从uri中获取参数 :后端:[FromUri]

2、从uri中获取数组参数:后端:[FromUri]string[] type  前端:type[]=1&type[]=2&type=3

3、从uri中获取List<Key,Value>参数:

   后端:[FromUri]List<FilterRequest> filters

 /// <summary>
   /// 参数对
   /// </summary>
   public class FilterRequest
   {
       /// <summary>
       /// 参数名
       /// </summary>
       public string Key { get; set; }
       /// <summary>
       /// 参数值
       /// </summary>
       public string Value { get; set; }
   }

  前端:api/smartfind/search?country=us&filters[0].key=color&filters[0].value=red&filters[1].key=color&filters[1].value=black

4、linq to entity 左连接查询  left join

 var temp = from m in entity.mediameta
                           join ma in entity.mediameta_accessory
                           on m.ID equals ma.MediaMetaID
                           where ma.PN == pn
                          && m.Status == (int)StatusType.Public
                          && m.FileType == "png"
                           join i in entity.imagefacet
                            on ma.ImageFacetID equals i.ID into facets
                           from facet in facets.DefaultIfEmpty()
                           select new
                           {
                               pn = pn,
                               url = HTTP + m.Url,
                               imagefacet = facet.Name,
                               type = m.Type
                           };

  5、字符串反序列化为对象

var object= jss.Deserialize<ObjectDto>(str);//直接是对象。传递{"color":"red","Usb":"mirco"}。接收转为

Color{get;set;};Usb{get;set;}
var object= jss.Deserialize<Dictionary<string, string>>(str);//键值对对象。传递&filters={"color":"red","USB":"mirco"}。接收转为

 /// <summary>
   /// 参数对
   /// </summary>
   public class FilterRequest
   {
       /// <summary>
       /// 参数名
       /// </summary>
       public string Key { get; set; }
       /// <summary>
       /// 参数值
       /// </summary>
       public string Value { get; set; }
   }