For EF database update, update the settings of the specified field, ef Field
1. Set the update field for EF and the new database
When EF is submitted to the database, some fields may not want to be updated, or you can update a model to the database by yourself!
1. Update data without updating some fields
/// <Summary> /// specify the update field in the database /// </summary> [HttpGet] public HttpResponseMessage alterUserInfo (int id) {// query and modify var user = DbContent. k_user.Where (o => o. id = id ). firstOrDefault (); user. name = "Week"; // you do not want to submit this attribute to the database to modify the user. age = 1; // set a field of a model in the container space not to be submitted to the database. // DbContent. the Entry is the entire object DbContent to be updated to the database. entry <k_user> (user ). property ("age "). isModified = false; DbContent. saveChanges (); return returnStringData (user. name );}View Code
2. Update method optimization (database update is not submitted when the attribute is null)
3. directly add model updates