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

Build Custom Method to Fill Data for Data Access

1 Answer 50 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Olivier
Top achievements
Rank 2
Olivier asked on 14 Jan 2015, 03:43 PM
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})
                            orderby(cOrder)
                            .ToList();               
 
 
       
            //======================================================
        }
        return oUserList;
    }


thanks Olivier

1 Answer, 1 is accepted

Sort by
0
Kristian Nikolov
Telerik team
answered on 16 Jan 2015, 03:21 PM
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")
    .Where(where)
    .Select(select)
    .OrderBy(orderBy);

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.

Regards,
Kristian Nikolov
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
General Discussions
Asked by
Olivier
Top achievements
Rank 2
Answers by
Kristian Nikolov
Telerik team
Share this question
or