How can I convert this code to Entity Framework?
update cachieroperation set last_used = getdate()+'0:8:0' where id = 14
How can I convert this code to Entity Framework?
update cachieroperation set last_used = getdate()+'0:8:0' where id = 14
Should be something like(I don't know what your classes are called):
using(var context = new SomeEntities())
{
CarrierOperation carrierOperation = context.CarrierOperations.SingleOrDefault(co=> co.id == 14);
if(carrierOperation != null)
{
carrierOperation.last_used = DateTime.Now.AddMinutes(8);
context.SaveChanges();
}
}
You can use ExecuteQuery
for executing queries directly against the database:
string query = "update cachieroperation set last_used = getdate()+'0:8:0' where id = 14";
context.ExecuteQuery<cachieroperation>(query );
For more info, see Microsoft Docs on ExecuteQuery