LINQ Query

string query = @"select i.ID as ItemID, i.Name as ItemName, i.Description as Briefinfo, a.Name as Area,

                            '" + Vpath + @"' + i.Image as Vimg 
                            from Item i
                            inner join Area a
                            on i.AreaID = a.ID
                            where i.ID in (select Distinct v.ItemID 
                                          from Video v 
                                          where v.SendType = '" + (int)Enums.VideoSendType.已发布 + @"' and v.Status = '"
                                                    + (int)Enums.FileStatus.启用 + @"' and v.UploadTime > '" + DateTime.Now.AddDays(-6) + @"')  and i.Status = '1'
                            order by (select top 1 v.UploadTime from Video v 
                                      where v.ItemID = i.ID
                                      order by v.UploadTime desc) desc";

var list = db.ExecuteQuery<ExportItem>(query).AsEnumerable<ExportItem>().ToList();


var list = (from v in db.Video
                        join i in db.Item on v.ItemID equals i.ID
                        join c in db.Category on i.CategoryID equals c.ID
                        join sv in db.ServerToVodOrLive on v.ID equals sv.VideoID
                        join s in db.ServerTbl on sv.ServerID equals s.ID
                        where i.CategoryID == categoryID && i.Status && v.Status == (int)Enums.FileStatus.启用 && v.SendType == (int)Enums.VideoSendType.已发布 && c.Status

                        select new ExportItem
                        {
                            Name = c.Name,
                            ItemID = i.ID,
                            ItemName = i.Name,
                            Description = i.Description,
                            Type = c.Type,
                            Server = s.IP + ":" + s.ServerPort,
                            Issued = i.Years.ToString(),
                            Briefinfo = i.Description,
                            Area = i.Area.Name
                        }).Distinct().OrderByDescending(e => e.ItemID).ToList();
            return list;

你可能感兴趣的:(SQL Server,LINQ)