This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19910|Reply: 0

[Source] Similarities and differences between DeleteOnSubmit and DeleteAllOnSubmit

[Copy link]
Posted on 6/25/2015 10:38:09 AM | | |

a. DeleteOnSubmit: Deletes an entity from the datacontext object and executes the changes when SubmitChange().

b. DeleteAllOnSubmit: Deletes a collection of entities from the datacontext object and executes the changes when SubmitChange().

Example:

    protected void btnDelete_Click(object sender, EventArgs e)

    {

        UsersDataContext dal = new UsersDataContext();

        User user = dal. Users.FirstOrDefault(s => s.UserName == "Tom");

        if (user != null)

        {

            dal. Users.DeleteOnSubmit(user); Delete individual pieces of data

        }

        var q = dal. Users;

        dal. Users.DeleteAllOnSubmit(q); Delete the dataset

        dal. SubmitChanges();

    }

Note: The above two functions must follow the SubmitChange() function to delete data from the database. We can understand it in layman's terms: the above two functions are only equivalent to a Sql statement, and SubmitChange() is equivalent to executing this Sql statement.




Previous:asp.net have the GridView highlight the selected rows and set the selected rows to be highlighted
Next:The handler "PageHandlerFactory-Integrated" has an error module "Manage...
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com