简介:我想找到一种使用Entity Framework和MySQL进行随机排序的方法(这很重要).该解决方案不应使用原始SQL查询或在从数据库加载所有值后进行排序.
我尝试过的:
我想从使用NewGuid()获得该答案的随机顺序.
码:
var query = from e in context.Table
orderby Guid.NewGuid()
select e;
var test = query.FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
总是抛出异常:
An error occurred while executing the command definition. See the inner exception for details.
Inner exception:
FUNCTION MyDatabase.NewGuid does not exist System.Exception {MySql.Data.MySqlClient.MySqlException}
Run Code Online (Sandbox Code Playgroud)
似乎问题是MySQL没有NewGuid()函数.
我怎样才能通过MySQL函数RAND()来代替NewGuid().换句话说,如何RAND在Entity Framework中使用自定义功能?
当我使用linux并尝试使用此脚本将文件上传到远程服务器时,一切都很好.但如果我使用Windows,那么脚本无法正常工作.脚本:
$url="http://site.com/upload.php";
$post=array('image'=>'@'.getcwd().'images/image.jpg');
$this->ch=curl_init();
curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 30);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($this->ch, CURLOPT_POST, 1);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post);
$body = curl_exec($this->ch);
echo $body; // << on Windows empty result
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
PHP 5.3
Windows 7 - 不工作,Ubuntu Linux 10.10 - 工作
我知道准备好的语句的威力,但我不能在这里使用它。我通过 HTTP 而不是通过 JDBC 将 sql 查询发送到外部服务器。如何转义 SQL 查询的字符串?有没有办法通过 JDBC 来做到这一点?或者我应该为此使用自定义类/函数?
ps 另外,我还连接到其他数据库,因此我可以使用 JDBC 函数。