1

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

SuperManSL
  • 1,306
  • 2
  • 12
  • 17
  • 5
    You should probably have a look at [OData / WCF Data Services](http://msdn.microsoft.com/en-us/library/cc668792(v=vs.110).aspx) - it sounds like you might be reinventing a wheel? – StuartLC Nov 19 '14 at 17:25
  • Let just say that wheel was invented later, when structure of this WFC and asp.net app was already written. What can I say, I'm not the one who make this kind of decisions. – SuperManSL Nov 19 '14 at 19:17

1 Answers1

0

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

al_amanat
  • 615
  • 3
  • 10