Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8492221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:39:19+00:00 2026-06-10T22:39:19+00:00

I have database first application in mvc3. There is Rating table, it has ID

  • 0

I have database first application in mvc3. There is Rating table, it has ID and Value property in integer type. Count is 5 always. I want enter new Value, set it to the last element of Ratings and every element’s value pass to before element’s vaule. Values are sliping from last to first.

public ActionResult UpdateRating( int newValue )
{

var rating0 = db.Ratings.ElementAt( 0 );
var rating1 = db.Ratings.ElementAt( 1 );
var rating2 = db.Ratings.ElementAt( 2 );
var rating3 = db.Ratings.ElementAt( 3 );
var rating4 = db.Ratings.ElementAt( 4 );

rating0.Value = rating1.Value;
rating1.Value = rating2.Value;
rating2.Value = rating3.Value;
rating3.Value = rating4.Value;
rating4.Value = newValue ;

db.Ratings.Attach( rating0 );
db.ObjectStateManager.ChangeObjectState( rating0 , EntityState.Modified );
db.Ratings.Attach( rating1 );
db.ObjectStateManager.ChangeObjectState( rating1 , EntityState.Modified );
db.Ratings.Attach( rating2 );
db.ObjectStateManager.ChangeObjectState( rating2 , EntityState.Modified );
db.Ratings.Attach( rating3 );
db.ObjectStateManager.ChangeObjectState( rating3 , EntityState.Modified );
db.Ratings.Attach( rating4 );
db.ObjectStateManager.ChangeObjectState( rating4 , EntityState.Modified );
db.SaveChanges();
...
}

I got error db.Ratings.ElementAt(); line. How can i do this operation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:39:21+00:00Added an answer on June 10, 2026 at 10:39 pm

    replace with

    public ActionResult UpdateRating( int newValue )
    {
    
    List<Rating> ratings = db.Ratings.OrderBy(r => r.id)
                            .ToList();
    
    ratings[0].Value = ratings[1].Value;
    ratings[1].Value = ratings[2].Value;
    ratings[2].Value = ratings[3].Value;
    ratings[3].Value = ratings[4].Value;
    ratings[4].Value = newValue;
    
    db.SaveChanges();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database framework where I have two tables. The first table has
i have 3 Tables is my SQL Database: First Table: Room: ID <pk>, Roomname
So I have a database with a few tables. The first table contains the
I have an issue in entity framework code first, three table in database as
I have thought of creating my first database application for one of my projects
We are using MVC3 and EF in our application. We are following Database First
I am working on asp.net mvc3 application and have many records coming from database.
.NET newbie here. I have an MVC3 web application EF 4.1 Code First and
I have an MVC3 and EF 4 Code First application, which is configured to
I am creating my first ASP.Net MVC3 Application using Azure as DB Storage. There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.