title: Can I run SqlQuery on a View?
body: <p>So I have this query: </p>
  
  <pre><code>  var retval = db.v_AViewOfJoinedTables.SqlQuery("SELECT * FROM dbo.v_AViewOfJoinedTables WHERE @filter = '@value';", 
                                            new SqlParameter("@filter", columnname), 
                                            new SqlParameter("@value", value)).ToList();
  </code></pre>
  
  <p>But I'm not getting any result. If I run this query through SSMS, it returns data. I know if I use a table instead that it works. So can SqlQuery only work on tables or is something wrong my query or code?</p>
  
  <p>UPDATED CODE:</p>
  
  <pre><code>        SqlCommandBuilder scb = new SqlCommandBuilder();
          string columnname = userNameFilterType;
          string escapedColumnName = scb.QuoteIdentifier(columnname);
          string sqlQuery = String.Format("SELECT * FROM dbo.v_AViewOfJoinedTables WHERE {0} = '@username';", escapedColumnName);
          var retval = db.v_AViewOfJoinedTables.SqlQuery(sqlQuery, new SqlParameter("username", currentUser)).ToList();
          return retval.AsQueryable();
  </code></pre>