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?
replace with