I am looking for a good guide on the correct method of using Linq to Sql with WPF.
Most manuals relate only to basic principles, for example, how to display data from a database, but none of them found how to save back to the database. Can you answer or point me to a guide that can answer these questions.
I have a separate Data project because the same data will also be used on the web page, so I have a repository method. This means that I have a separate class that uses a DataContext, and there are methods like GetAllCompanies () and GetCompanyById (int id).
1) Where are the collections, is it best to return as IQueryable or do I need to return the list?
Inside the WPF project, I saw recommendations about wrapping a collection in an ObservabgleCollection.
2) Why should I use ObservableCollection and should I use it even with Linq / IQueryable
Some properties of linq objects must be editable in the application, so I set them in two-way mode. This will change the object in the observed set.
3) Is the object in the ObservableCollection still an instance of the original linq object and, therefore, this change is reflected in the database (when signatures are called)
I need to have some save method in the repository. But when should I call it? What happens if someone edits a field, but decides not to save it, moves to another object and edits it, and then click "Save." Does the original change not save? When it no longer remembers changes to the linq object object. Do I have an instance of the Datacontext class in each method, so it loses scope.
4) When and how to call the SubmitChanges method
5) Should I have a DataContext as a member variable of a repository class or method variable
To add a new row, I have to create a new object in the event (βnewβ button click) and then add it to the database using the repo method.
6) When I add an object to the database, there will not be a new object in the ObservableCollection. Somehow update.
7) I will not reuse the editing window when creating a new one, but I'm not sure how to dynamically change the link to the selected item from the list to this new object. Any examples you can specify.