Build Custom Method to Fill Data for Data Access

Thread is closed for posting
2 posts, 0 answers
  1. Olivier
    Olivier avatar
    146 posts
    Member since:
    Nov 2010

    Posted 14 Jan 2015 Link to this post

    Hello telerik team,

    I don't see , how can i build this kind of method for linq for telerik data access ?

    can you help me ?

    public virtual Type GetFillData (string cSelect, string cWhere, string cOrder, string cGroupBy)
            string cSql ="";
            cSql = "select "+cSelect+" from "+ this.TableName;
            if (! string.IsNullOrEmpty(cWhere)) {
                cSql += " where "+cWhere;
            if (! string.IsNullOrEmpty(cGroupBy))
            cSql += " group by "+cGroupBy;
            if (! string.IsNullOrEmpty(cOrder))
            cSql += " order by "+cOrder;
            if ( ! string.IsNullOrEmpty(cSql)) {
                var oUserList = (from user in this.DbContext.GeTable("mytable")
                                where (cWhere)
                                select new {cSelect})
            return oUserList;

    thanks Olivier
  2. Kristian Nikolov
    Kristian Nikolov avatar
    206 posts

    Posted 16 Jan 2015 Link to this post

    Hello Olivier,

    If I am understanding your scenario correctly, you wish to dynamically construct a LINQ query using string values to retrieve the required records from the database. If this indeed is the case you can make use of Telerik Data Access in combination with Dynamic LINQ as shown in this documentation article.

    In case you also need to dynamically specify what object should the query retrieve you can combine the Artificial API together with Dynamic LINQ. For example, consider a scenario where you have a persistent type Car in the EntitiesModel namespace. The Car type has properties such as CarID, Make, Model, TagNumber, etc. The following code snippet would retrieve the required information specified using string parameters:
    string where = @"CarID>10";
    string select = @"new(CarID, Make, Model)";
    string orderBy="Make";
    var cars = context.GetAll("EntitiesModel.Car")

    For more information regarding the general Dynamic LINQ syntax you can refer to this blog post.

    I hope this helps. In case you have additional questions do not hesitate to get back to us.

    Kristian Nikolov
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
Back to Top