Selecting Most Recent News Article In A Collection With Linq To Sql?
Aug 18, 2010
I have a bunch of news articles and I want to select the most recent one using Linq to Sql. I have an MVC action method like so
[ChildActionOnly]
public ActionResult LatestNews()
{
var article = mhndb.NewsArticles.Single();
return PartialView("LatestNews", article);
}
I would like to know the syntax for selecting the most recent item in the NewsArticles collection using Linq.
View 2 Replies
Similar Messages:
Jun 25, 2010
I don't know if "Web Forms" is the right place for my Question!!
anyway.. If I have a Default.aspx page, which is the Home Page of my website
and I want to insert some news in it (actually i want these news to be added in a certain Div/or part of the page).. >>> Recent News added by Admin for example
How to do that??
View 7 Replies
Mar 28, 2011
i'm using a strongly typed view with a custom viewmodel. this viewmodel contains a collection of books.
public IList<Books> Books { get; private set; }
i'm also passing a select-list to the view. however the DropDownListFor helper class doesn't automatically preselect the default value of the book.
@Html.DropDownListFor(m => Model.Books[i].AuthorID, Model.Author as SelectList)
everything else works, e.g. it does pass the selected value back to the controller.
i figured out a workaround by creating the select list in the viewmodel:
@Html.DropDownListFor(m => Model.Books[i].AuthorID, new SelectList(Model.AuthorList, "Value", "Text", @Model.Books[i].AuthorID.ToString()))
however i don't want to implement this workaround if there is a simpler solution. is there a way that the view can handle values from a collection?
View 2 Replies
Apr 3, 2010
I am working on How to display the News Updates on page inside Marquee as hyperlink and on click on the link i have to display the details of the selected News .
which approach i can display the particular section of the page ?
I have to disply the News from Database?
View 2 Replies
Aug 12, 2010
Imagine I have 3 classes (student has Marks which has subjects)
[Code]....
I got a List<Student> populated with all the student and nested collection of corresponding Marks and subjects.How do I, before binding this list to any grid, filter records to display only those students, who surely have appeared in subjects with name "X" and "Y"?I tried something like:
[Code]....
View 2 Replies
Aug 14, 2010
i have an array with id numbers (of the products) in it.
Like for example:
string[] productIds = { "5", "12", "2", "2" };
Now i want to select only the records that only have the id numbers from the array, is it possible?
View 7 Replies
Nov 8, 2010
i want to make a add news page that when my user write his news(in up.aspx) then his news shown in news.aspx.
what am i going to do ? what is the best way for writing this page ?
View 1 Replies
Mar 13, 2011
I'm constructing a query using linq, but I'm having trouble using a collection, i.e. where field in database = anything in the collection.
Below is an example of what I mean:
dim keywords as string ="test,test2,test3,cats,dogs,frogs"
Dim getKeywords = (From cp In myDataContext.pages
Where cp.pageKeywords = currentPageKeywords.Split(",")
The aim of the above code is to return all records where the "pageKeywords" field contains 1st keyword, or 2nd keyword, or 3rd keyword etc.
View 5 Replies
Jul 28, 2010
is there a way to update a column for all rows in a collection using linq like sql does it
eg. UPDATE myTable SET myColumn='newValue'
Also weighing options as to whether there is better performance using linq to sql for this or straight sql to DB via table adapters etc.
View 2 Replies
Nov 23, 2010
here my code-
List<ReservationSlotLimitDetailEntity> sorted = (from p in slotLimitCollection.OfType<ReservationSlotLimitDetailEntity>()
where p.DayOfTheWeek == dayOfTheWeek
select p).ToList<ReservationSlotLimitDetailEntity>();
I want to sort in such a way so that it will add on more temp column "DayName" based on condition such that if dayOfTheWeek==1 DayName=Monday and if dayOfTheWeek==2 DayName=Tuesday and so on.
View 1 Replies
Aug 13, 2010
I'm new to LINQ and have a problem with my query not showing me the Table Collection. I manually created my Cart class and specified the table attributes on each property (works fine for inserting records via LINQ see below). DataContext dc = new DataContext(Conn);
var q = (from c in dc.NOTABLES?? where ((c.UserID == userID)) orderby c.CreateDateTime Based on examples I would expect to see dc.Cart But I don't, so I tried to access it via dc.GetTable<Cart>() which at least gets me data but doesn't seem to convert the rows to my Cart object since this:
foreach (var cart in q) Log.Info("UserID: " + cart.UserID + " CartID: " + cart.ID.ToString());
blows up with a "Specified Cast is Not Valid" exception.
No Problem Inserting Also, I had no problem inserting data into the database:
DataContext dc = new DataContext(Conn);
Table<Cart> Carts = dc.GetTable<Cart>();
Cart aCart = new Cart();
aCart.UserID = userId;
aCart.Description = description;
aCart.CreateDateTime = System.DateTime.Now;
aCart.UpdateDateTime = System.DateTime.Now;
Carts.InsertOnSubmit(aCart);
Carts.Context.SubmitChanges();
View 1 Replies
Apr 5, 2010
I have a partial class extending my Entity Model. I'd like to write a method that returns a collection of types from my entity framework model. For example, I'd like to get all the states to populate a drop down list. So I've written a method called getallstates(), similar to the example below:
[Code]....
I tried returning a list of Objects, and a list of states to my calling method to be used to bind to a drop down list. However I get an error that:
Server Error in Application. Unable to cast object of type 'System.Data.Objects.ObjectQuery to type 'System.Collections.Generic.List`1[System.Object]'.
What should my return type be for this function?
View 2 Replies
Dec 16, 2010
I'm new to linq. here is the scenario i need to write query for.I have a "Candidate" table with a varchar property "Skill"I have the table OR-mapped with LINQ to SQL on dbml file. Now I want to write linq query that:Selects all Candidates that have skill containing any of the keywords from ("asp.net","php","java")
View 1 Replies
Oct 13, 2010
I've got a gridview that will allow clients to edit options they've already entered on another page. The gridview has three radio buttons in it each with a value of 1,2,3. The option value in the dataset is 1,2 or 3 respectively. I would like to have the radiobutton with the corresponding value selected in the gridview so they can see what they previously chose and will then be able to edit, if they wish.
Here's my code so far:
[Code]....
View 6 Replies
Jul 26, 2010
I have a list of objects that I want to bind to a gridview. Creating that list and binding it works fine for most of the public properties in that list.
There are some objects contained in each of those objects... for instance there is an Address object.
object.Address.Line1;
object.Address.Line2;
When I bind this to my gridview, I have no issues with stuff like object.DateRegistered, but how can I access things like object.Address.WhatEverProperty? I always get this error:
"A field or property with the name 'xxx.xxxx' was not found on the selected data source."
View 7 Replies
Mar 31, 2010
I want to know that how i use the collection class for storing some data and save it letter in the data base.
View 4 Replies
Jul 22, 2010
I have a BlogPost table by which i post blog on my website, this is the structure of BlogPost Table:
BlogPostID int Unchecked
LanguageID int Unchecked
BlogPostTitle nvarchar(200) Unchecked
BlogPostBody nvarchar(MAX) Unchecked
BlogPostAllowComments bit Unchecked
CreatedByID int Unchecked
CreatedOn datetime Unchecked
[code]...
View 13 Replies
Oct 20, 2010
've got a slightly odd requirement that I'm not sure how to properly articulate.I essentially want to prioritise the most recent requests to an ASP.Net handler. I'm not sure if this should be client-side or server-side. I'm leaning towards server side to ensure it's enforced on all clients.So, as requests come in, they're essentially stacked according to some internally-defined time interval, per client. Then, the top of the stack (most recent) request is processed first.
View 1 Replies
Mar 25, 2011
I have an ASP.NET app with lots of textboxes all over the page that need updating at various points through program execution.
These textboxes actually belong to a certain class, so for easy updating I thought I could create a Dictionary(Of string, object) and add the control.ID and the control to it and then for updating do something like this:
(in case of updating textbox.text):
[code]....
However the text property of the textbox does not actually get updated. I'm mainly trying to avoid having to manually do textbox.text = somestring for each one of my textboxes every time I have to update them.
View 3 Replies
Apr 21, 2010
I'm developing a Asp.Net website and I need to display the four most recent tweets from a group of users (around ten) that will be set in the admin area of the website. I know twitter has an API, but I don't know where to start.
View 3 Replies
Sep 29, 2010
How do I set the number of Most Recent Projects displayed. I have tried the obvious -- Tools-Options..... but I cannot see it.
View 9 Replies
Oct 18, 2010
In the stord procedure below. I am retreiving all the records for that 1 deal. What I want is to retrieve the most recent record hence the one with the most recent in the AddedDate field.
How can I accomplish this?
(
@DealID int)
AS
SET NOCOUNT ON
SELECT deals_Comments.CommentID, deals_Comments.AddedDate, deals_Comments.UserID, deals_Comments.AddedByEmail, deals_Comments.AddedByIP, deals_Comments.DealID, deals_Comments.Body, deals_Comments.SBody,
ROW_NUMBER() OVER (ORDER BY deals_Comments.AddedDate DESC) AS RowNum
FROM deals_Comments
WHERE deals_Comments.DealID = @DealID
View 6 Replies
Jan 27, 2010
Last night I started working on an NHibernate provider. I'm creating a criteria that several records will match, however I only want to return the most recent record (the record with the largest Id). I thought UniqueResult() would do this it cannot be used if a list would be returned otherwise.
I could theoretically select the full list and then return the desired record, but I believe there is a better way.
View 2 Replies
Feb 28, 2011
I have a table which have different records in it, When user click on each record I save the primary key of the record to another table (recent viewed) with short date and time. It checks first if that record is already there so it just update the data and time but if record is not yet there then it will add it.
I want that the recent viewed table only store 15 records in it. Not more then 15 and most oldest added record should be overwrite. Is that possible in MS SQL server 2008?
View 1 Replies
May 7, 2015
how to display recent viewed product in gridview / listview,first one if any user click on any one product on listed all product then and redirect new page where user can view full details of single product ,its going fine but when user back to home then i want to show recent viewed product , recent view product should not save in db ,just save in temporary datatabee and view in gridview , if user see 10 product then it save in temporary datatable and bind into gridview all 10 product.
View 1 Replies