This is a migrated thread and some comments may be shown as answers.

Ordering with localized data entities

6 Answers 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ale
Top achievements
Rank 1
Ale asked on 12 Mar 2014, 10:38 AM
Hello everyone, I'm trying to populate a grid with localized data.
My codefirst entity framework database look like this:

public class Prod
{
    public int ProdId { get; set; }
    public int Quantity { get; set; }
 
    //Other Properties & Navigation Properties
 
    public ICollection<ProdLang> ProdLangs { get; set; }
}
 
public class ProdLang
{
    public int ProdLangId { get; set; }
    public int LangId { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
 
    //Other Properties
 
    public int ProdId { get; set; }
    public Prod Prod { get; set; }
}

I want to show in my kendo grid Collection of Product with ProdLang properties for current user language (eg. Name, Description)
For doing that i buil a flattened class, like this:

public class ProdView
{
    public int ProdId { get; set; }
    public int Quantity { get; set; }
 
    public string Name
    {
        get
        {
            return ProdLangs.Single(pl => pl.LangId == langId).Name;
        }
    }
 
    public string Description
    {
        get
        {
            return ProdLangs.Single(pl => pl.LangId == langId).Description;
        }
    }
    //Other Properties & Navigation Properties
 
    public ICollection<ProdLang> ProdLangs { get; set; }
}

My problem is that I want to let user to order & paging data, but I don't want to load entire collection everytime I have to display grid and pass it to "ToDataSourceResult" method.

There is a way for loading from the DB only the desired data?

Thanks

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 14 Mar 2014, 08:33 AM
Hello Alessio,

Could you please clarify what loading the entire collection means? The ToDataSourceResult method uses LINQ expressions to perform paging, sorting etc and if given an IQueryable will execute those in the DB thus retrieving only one page of data.

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ale
Top achievements
Rank 1
answered on 14 Mar 2014, 08:59 AM
Hello Atanas,

In my application I use Repository pattern with Unit of Work. I prefer not expose IQueryable on Repository, because I read there are some security problem.

My Repository exposes a method that take a DataSourceRequest and perform filtering\sorting\... directly on DB, and return an IEnumerable<T>. I think that even using IQueryable there is that problem, because ModelView column Description doesn't exist in my DB.

Can you suggest me a possible solution. Thank you.
0
Atanas Korchev
Telerik team
answered on 14 Mar 2014, 09:36 AM
Hi Alessio,

It is still not clear what the problem is. Could you please clarify? How does the localization cause retrieval of all items from the database? How is this related to Kendo UI ?

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ale
Top achievements
Rank 1
answered on 14 Mar 2014, 09:47 AM
Hello Atanas,

basically my question is:

With my entity structure, how can I show ProdLang Description on Prod Grid? And how can I order data on Grid by this (or other) field?
0
Ale
Top achievements
Rank 1
answered on 14 Mar 2014, 09:50 AM
Hello Atanas,

basically my question is: With my entity structure, how can I show ProdLang Description field in Prod grid? And how can I order by a field of a ProdLang field?
0
Accepted
Atanas Korchev
Telerik team
answered on 14 Mar 2014, 09:55 AM
Hi Alessio,

You need to create a bound grid column to the required property. The grid will display it. As for ordering - you need to implement this with custom code since you don't seem to be using ToDataSourceResult. How you you implement ordering by a localized field if the grid weren't involved? Perhaps the same approach can be used with the grid.

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Ale
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ale
Top achievements
Rank 1
Share this question
or