Pass WHERE/clause to WCF service

551 views Asked by At

I have method on WCF service that accepts four parameters. Method will handle update statement for updating data in MS SQL database. The issue I ran into is that I can't find a way to send clause as parameter. The thing is that WCF can't accept objects of QueryBuilder because they can not be serialized. Method on WCF will be called from an asp.net client page (no ajax stuff).

  1. table (string)
  2. columns (string[])
  3. values (string[])
  4. clause (????)

WHERE clause should be something like three dimensional array example:

clause.Add("users.id","=",1);  

My current method with missing clause

public bool SqlUpdate(string table, string[] columns, string[] values,??? clause)
{
    bool success = false;
    DbDataReader dbDataReader = null;
    try
    {
        DbCommand command = new System.Data.SqlClient.SqlCommand();
        UpdateQueryBuilder update = new UpdateQueryBuilder();
        update.SetTable("users");
        update.AddAssignment("firstName", "ChangedName");
        //loop through clauses (it can have multiple clauses) if necessary
        update.Where = new SimpleWhere("users", "id", Comparison.Equals, 4);      //this is where I need to input clause  
        success = true;
    }
    catch (Exception ex)
    {
        WriteError(ex.ToString());
        success = false;
    }
    return success;
}

UpdateQueryBuilder() is class for creating parameterized query by code-engine.com. Source code can be found here

1

There are 1 answers

1
al_amanat On

Look to Dynamic Linq (System.Linq.Dynamic). You can pass a query string from client to server and then invoke it using Dynamic Linq. http://dynamiclinq.codeplex.com/documentation