Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>if you're using Entity Framework, not LINQ to SQL, there is wonderful Entity Sql and you can use it as</p> <pre><code>object DynamicQuery(string fieldName, object fieldValue) { string eSql=string.Format("it.{0} = @param", fieldName); return db.Where(eSql, fieldValue).FirstOrDefault(); } </code></pre> <p>hope this helps</p> <p>MSDN has the following example, you see that you can dynamicly change strings used to access ProductID field, and as far as i remember event rename it.</p> <pre><code>using (AdventureWorksEntities advWorksContext = new AdventureWorksEntities()) { try { // Use the Select method to define the projection. ObjectQuery&lt;DbDataRecord&gt; query = advWorksContext.Product.Select("it.ProductID, it.Name"); // Iterate through the collection of data rows. foreach (DbDataRecord rec in query) { Console.WriteLine("ID {0}; Name {1}", rec[0], rec[1]); } } catch (EntitySqlException ex) { Console.WriteLine(ex.ToString()); } } </code></pre> <p>Also you can even do the following (again from MSDN)</p> <pre><code>using (AdventureWorksEntities advWorksContext = new AdventureWorksEntities()) { string myQuery = @"SELECT p.ProductID, p.Name FROM AdventureWorksEntities.Product as p"; try { foreach (DbDataRecord rec in new ObjectQuery&lt;DbDataRecord&gt;(myQuery, advWorksContext)) { Console.WriteLine("ID {0}; Name {1}", rec[0], rec[1]); } } catch (EntityException ex) { Console.WriteLine(ex.ToString()); } catch (InvalidOperationException ex) { Console.WriteLine(ex.ToString()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload