实战技术总结

1.选择单一条记录

   var Prize = con.Prizes.Where(e => e.PrizeType == 0).Select(p => new { id = Guid.NewGuid(), P = p }).OrderByDescending(p => p.id).FirstOrDefault().P;

2.提示

AjaxResult 文件:

    public class AjaxResult
    {
        public int Status { get; set; }
        public string Message { get; set; }
    }
    public class AjaxResult<T> : AjaxResult
    {
        public T Data { get; set; }
    }

引用:

 AjaxResult<ScratchModel> result = new AjaxResult<ScratchModel>
            {
                Status = -1,
                Message = "您没有中奖,欢迎下次再来。",
                Data = new ScratchModel
                {
                    Category = 0,
                    PrizeScore = 0,
                    PrizeTitle = null,
                    PrizeDescription = null,
                    ImageURL = null
                }
            };

model 类型:

    public class ScratchModel
    {
        public PrizeCategory Category { get; set; }
        public int PrizeScore { get; set; }
        public string PrizeTitle { get; set; }
        public string PrizeDescription { get; set; }
        public string ImageURL { get; set; }
    }

3.SQl

 string sql = string.Format("select  Name,Point from UserPointsByPointSource where PointSource={0} and UserId='{1}'", (int)PointSource.Friend, UserProfile.Id);
 model.UserPoints = context.Database.SqlQuery<UserPoints>(sql, new object[] { }).FirstOrDefault();

4. SQL 语句

获取前10 条去重复ID

  select top 10 UserId, max(CreateTime) as MaxTime  from UserPrizes  group  by UserId order by MaxTime  desc

select top 10 C.Id,C.Name,C.HeadImage  from (
 select top 50 k.UserId,max(k.CreateTime) as MaxTime  from
(
   select u.UserId,u.CreateTime from
   (
      select  UserId,PrizeId,CreateTime from  UserPrizes
    ) u  left join Prizes p on u.PrizeId=p.Id  where p.Category=4 and u.UserId is not null
)k   group  by k.UserId order by MaxTime  desc
) t  left  join CPCUsers c  on t.UserId=c.Id  where c.Id is not null

posted @ 2016-08-18 16:58  李寒星  阅读(188)  评论(0编辑  收藏  举报