CRUD in Winforms with linq-to-sql

I have a simple winforms application that I connect to my database using linq-to-sql.

I created the classes directly from the database, and I have a DataAccess class that wraps my datacontext and can give me everything I need.

I have a view that uses a data source object to populate a DataGridView and a set of related text fields, etc. for my entity (lets call it EmployeeView)

The view loads all existing rows, and as I click on the grid, the fields are updated accordingly.

If I changed the fields, the changes will be saved using the record changes, but I'm not sure how to save the changes at my data access level. How can I determine which records are dirty and need to be saved? How can I save them? What is the best way to add new entries? Delete entries?

I can find many resources on the Internet, but not one of the examples that I need. Can someone help me with some basic templates or point me to a good place?

+3
source share
1 answer

LINQ-to-SQL, , , (, Employee), , () . Employee , "", DataContext.SubmitChanges() .

List<Employee> employees = (from e in dataContext.Employees where e.Salary > 50000 select e).toList();

foreach(var employee in employees)
{
  employee.CanAffordToyotaPrius = true;
}

dataContext.SubmitChanges();

DataContext - DataGridView, - LINQ-to-SQL, , , , LtS.

+5

Source: https://habr.com/ru/post/1757441/


All Articles