(18)
Category:2019 software
Category:Face recognition software
Category:Image manipulation software
Category:Pattern matching algorithms
Category:Multimedia software
Category:Video analysis software
Category:Zoological media
Category:Software using the BSD licenseQ:
Commit query on a Linq2SQL Model
I have a question about a query that I use in Linq2SQL.
Can I commit this query?
public void EditUser(int id)
{
using (MyDB db = new MyDB())
{
DataClasses1DataContext dc = new DataClasses1DataContext(db);
User user = dc.Users.Single(u => u.Id == id);
if (user!= null)
{
dc.Entry(user).State = System.Data.EntityState.Modified;
dc.SaveChanges();
}
}
}
I saw that there are exceptions when I execute it from another method, but how can I commit this query?
A:
In order to commit the changes, you must add them to the DataContext, like so:
public void EditUser(int id)
{
using (MyDB db = new MyDB())
{
DataClasses1DataContext dc = new DataClasses1DataContext(db);
User user = dc.Users.Single(u => u.Id == id);
if (user!= null)
{
dc.Entry(user).State = System.Data.EntityState.Modified;
dc.SubmitChanges(); ac619d1d87
Related links:
Comments