public override void GetComments(Gallery gallery) { using (TransactionContext context = TransactionContextFactory.EnterContext(TransactionAffinity.NotSupported)) { IDataSource dataSource = DataSourceFactory.GetDataSource("DbGalleryProvider"); IDataCommand cmd = dataSource.GetCommand("GetComments"); cmd.Parameters["galleryId"].Value = gallery.ID; IDataReader reader = cmd.ExecuteReader(); try { while (reader.Read()) { Comment item = new Comment(new Guid(reader["id"].ToString())); item.Author = reader["author"].ToString(); item.Content = reader["content"].ToString(); item.DateCreated = Convert.ToDateTime(reader["dateCreated"]); item.Title = reader["title"].ToString(); item.IPAddress = reader["ipAddress"].ToString(); gallery.AddComment(item); } } finally { if (!reader.IsClosed) reader.Close(); } } }
public override void GetComments(Gallery gallery) { if (gallery == null) throw new ArgumentNullException("gallery"); GalleryDataContext db = new GalleryDataContext( ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString); Table<Comment> comments = db.GetTable<Comment>(); var query = from comment in comments where comment.ParentID == gallery.ID orderby comment.DateCreated descending select comment; foreach (var row in query) { gallery.AddComment(new Comment(row.ID) { Author = row.Author, Content = row.Content, DateCreated = row.DateCreated, IPAddress = row.IPAddress, Title = row.Title }); } }