Order rows with Entity Framework

asp.net asp.net-mvc c# entity-framework-6 sql

Popular Answer

In order to act swiftly, I would plan the database so that the primary key does not automatically increase and save the data so that the id is assigned in accordance with the precise position. Place an IF, of course, to confirm that it is available, and if I were to begin a cycle of review for the cascade of ensuing ID or positioning the value traded at the conclusion.

for instance

MyTable table = myDb.MyTable.Find(id);  //position
if (table==null)
{ table.id=position; table.Field=value; myDb.SaveChanges() }  
else
{
var temp = table.id;
var max = table.count(x=> x.id).value;
table.id=max+1;myDb.SaveChanges();
table.id=id; table.Field=value; myDb.SaveChanges();
}

I apologize if the translation is poor.

0
11/10/2015 9:13:47 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow