Read data from a DataTable into contract RRS feed

  • Question

  • Hi,

    I'm trying to read a data from DataTable into Entity Framework contract.

    By linq, I can implemet it as below:

    var TestResults = contractMediator.QueryContracts<ITestResult>(); var query = TestResults.Where(testResult => testResult.ID.ToString().Equals(testExecutionID.ToLower()) ).OrderBy(testResult => testResult.TimeStamp); if (!query.Any()) return null;

    else { ITestResult[] testResults = query.ToArray<ITestResult>(); object[] testResultsArray = new object[query.Count()]; for (int i = 0; i < testResultsArray.Length; i++) { testResultsArray[i] = (object)(new TestResultContractWrapper(testResults[i])); } return testResultsArray;


    The above way is working fine, But I'm trying to do the same thing by reading the data using SQL query:

    SqlConnection connection = new SqlConnection("ConnectionString");
                    string commandText = string.Format("Select {0} from TestResults {1}", select, (!whereClause.ToString().Equals(string.Empty)) ? "where " + whereClause.ToString() : string.Empty);
                    SqlCommand cmd = new SqlCommand(commandText, connection);
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataSet ds = new DataSet();

    Is there any way to implement the code in the above else block by replacing query in ds.Tables[0]?



    Wednesday, April 10, 2013 1:18 PM