public class test { public static bool Process() { using (MyContext context = new MyContext()) { var query = (from c in context.MyContents join v in context.MyContentVersions on new { contentId = c.ContentId, verGmt = (DateTime)c.PubVerGmt } equals new { contentId = v.ContentId, verGmt = v.VerGmt } where c.PubVerGmt != null && c.CatId == ConfigHelper.CatId && System.Data.Objects.SqlClient.SqlFunctions.DateDiff("day", v.VerGmt, DateTime.Now) < ConfigHelper.Days select new { ContentId = v.ContentId, VerGmt = v.VerGmt, Body = v.Body, Format = c.FormatId, CatId = c.CatId }).OrderByDescending(a => a.ContentId); IQueryable<dynamic> q = query as IQueryable<dynamic>; int maxNumberOfImage = ConfigHelper.MaxNumberOfImage; if (maxNumberOfImage > -1) { q = q.Take(maxNumberOfImage); } return SaveImages(q); } } private static bool SaveImages(IEnumerable<dynamic> contents) { string filename = ""; foreach (var item in contents) { filename = item.CatId + "-" + item.ContentId.ToString(); using (MemoryStream memStream = new MemoryStream(item.Body)) { Bitmap bitmap = new Bitmap(memStream); bitmap.Save(filename, ImageHelper.GetImageFormat(item.Format)); } } return true; } }
Tuesday, July 5, 2011
How to pass anonymous type as a method parameter using dynamic with LINQ
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment