I'm giving OpenAccess a try. I have created a model project using the ver 2 templates so that my business object's collections are of type TrackedBindingList(Of T). This seems to be working well so far in a DataGridView.
But what if I want to load a grid with a collection of business objects, do some operations on one or more of them, then hit Save (calling context.SaveChanges). I can't figure any way to created a tracked collection of business objects (or entities).
At the context level, a collection of Employees, is returned as an IQueryable(Of Employee), via the GetAll Function, which doesn't appear tracked by the context.
6 Answers, 1 is accepted
Thank you for your interest in Data Access.
In general, the context endpoints (IQueryable(of T)) are tracked out-of-the-box. When you retrieve objects through them, modify them, and than call the SaveChanges method, the changes will be persisted to the database without any additional effort on your side. This section in our documentation will give you more details about the CRUD operations with Data Access.
Regarding the scenario on your side, I was unable to completely understand it and therefore I kindly ask you to elaborate a little bit more on the subject:
- What are these business objects?
- How do you retrieve them?
- Do you use some sort of DTOs (custom types) or the persistent types themselves?
Additionally, for the basics of databinding with Data Access, I would recommend you to review the WinForms Quick-Start scenario in our documentation and its implementation in Samples Kit (the Basic Data Binding with Windows Forms sample).
I am looking forward to your feedback.
Regards,
Doroteya
Telerik
Indeed, they are tracked. I'm not sure why it wasn't working for me before.
What I should have asked is, why aren't such collections sortable in a DataGridView?
Neither IQueryable(Of T) nor TrackedBindindList(Of T) appear to support IBindingList's sorting.
My business objects are just classes generated by OpenAccess in a database-first workflow. Nothing mysterious about them.
I retrieve them in the normal fashion:
Dim prod = context.Products.Where(Function(p) p.ProductID = 1).SingleOrDefault ...or...
Dim prods = context.Products...whatever the case may be.
If I bind prods to a DataGridView using a BindingSource and/or BindingNavigator, sorting is not supported on the collection.
What do you recommend? Thank you for your time. Please try to answer a little quicker than before :) Today would be nice...
Regarding feedback:
So far, I find Data Access to be a fine ORM, as compared to Entity Framework. The API is less cluttered than even EF's DbContext. It handles object generation across junction tables in the datastore quite well (I'm doing database-first).
I do note some odd behavior when generating an object based on a table which contains a column of type byte array. A warning states, "Explicit change tracking required for the array field...etc.", Line: 16707566, Column: 1
Double clicking on this warning results in an exception, because of the HUGE line number: "The operation could not be completed. The parameter is incorrect."
What is meant by the warning that explicit tracking is required? How do I explicitly track such a field? Then, how do I get rid of the warnings?
I also note that generated classes contain an Import of the model namespace. This seems unnecessary.
Also, your emitted VB is really (really) bad. It looks like C#, which quite defeats the purpose. Y'all are in serious need of the services of a professional VB developer :)
In spite of the problems, I see promise in it - for two main reasons:
1. Telerik Data Access seems to have very good performance.
2. Telerik Data Access targets SQL Server 2000.
Thank you for the kind words and I am glad you found the details about the validation error.
Regarding sorting and filtering of the results returned by the IQueryable endpoints, handling this in a WinForms scenario with a binding source requires implementation on your side. Here and here you can check what the recommended way of doing these tasks is.
I hope this helps. Let us know if you need further information.
Regards,
Doroteya
Telerik