0
votes

I need some help to understand the best way to represent datas from SQL DB to SyncFusion grid control.

The Animal table contains foreign keys for eye color, coat color...

I can add the ObjectSet from ObjectContext generated by DevArt as DataSource for SyncFusion sfDataGrid. As we can see on the picture, we see the foreign keys.

SQL Table content

If I want to have the {rec.Coat.Name} instead of {rec.CoatId} displayed, I have to use UnboundColumn (enter link description here). But using this way cause some troubles : SyncFusion component cannot sort UnboundColumn. From the editor, there's no plan to implement it.

So, what's the good way using Entity Framework to convert datas (and convert foreign keys) from SQL table to the good DataSource for Winform control ?

Thanks for help.

Vincent

3

3 Answers

1
votes

We are using the DataView’s Sort property to sort the records in SfDataGrid. As you know, unbound column is not an actual column in the DataTable which is bound to SfDataGrid. So, even though you apply the sorting, it is not getting sorted and throwing exception from framework since that corresponding column is not available in actual DataTable. So, as per you requirement, we can’t provide the support using DataTable as the DataSource.

On the other hand, we would like to suggest you that you can use the Entity framework and assign the entity collection to the SfDataGrid. SfDataGrid supports sorting and all other data operations for unbound column for entity framework. Because, we are handling our own logics for the sorting and all other data operations. You can refer the below article to know about how to use the SQL and Entity framework.

https://dzone.com/articles/receive-notifications-with-new-values-when-table-r

SQLTableDependency.OnChanged method will be called whenever the server side data is updated. So that, you can update the entities in the application based on that. Can you please go through the above article and let us know whether that suits your requirement?

Regards,

Vijayarasan S

1
votes

Try using Join in your LINQ query to replace rec.CoatId with rec.Coat.Name in the result set: https://docs.microsoft.com/en-us/ef/core/querying/complex-query-operators .

0
votes

Here is the solution :

var query0 = from myanimal in this.ctx.Animals
             join animalCoat in this.ctx.Coats on myanimal.CoatId equals animalCoat.Id
                 select new
                 {
                     OwnerName = myanimal.FullName,
                     myanimal.Male,
                     CoatName = animalCoat.Name,
                 };
this.sfDataGrid1.DataSource = query0.ToList();

Thanks to @Devart support and @Vijayarasan from SyncFusion company :)