LINQ to SQL and Windows Forms Binding
What is the proper way for binding LINQ to SQL queries in Windows Forms controls?
Should I follow the standard way with BindingSource and handle the events to have 开发者_如何学Pythonchange tracking while various values are changing from the controls. This kind of binding will involve hierarchical object binding too, EntityRef<>, EntitySet<>.
Now for the designer, is it OK to create an object DataSource on the dbml domain model and use it on controls or should I just use code? I guess the designer way just speeds things up and that is good of course, but as we all know, speed sometimes is bad.
Binding using the BindingSource works well in my experience.
The only design problem you have is that the LINQ to SQL datacontext is build for "short term" usage. I've done it: used a LINQ to SQL datacontext for hours in a Windows Forms application across multiple forms. It works, but you know (and even sort of feel) that it is not the intentional use (for example, don't use Using
or Dispose()
statements on the datacontext).
This means that you should use the object for a single unit of work. For example, get information or send (multiple) updates to the database.
That was the moment I got very interessted in this article on MSDN, Data Retrieval and CUD Operations in N-Tier Applications (LINQ to SQL).
精彩评论