问题列表 - 第44364页

mongoDB像SQL一样运行查询!

    public IQueryable<T> GetRecords<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression, int from, int first) where T : class, new()
    {
        first = first == 0 ? 30 : first;
        return _db.GetCollection<T>(collectionName).Linq().Where(expression).Skip(from).Take(first);
    }
    var x = GetRecords<Event>(p => true, 0, 12222);
    string eventJson = new JavaScriptSerializer().Serialize(x);
Run Code Online (Sandbox Code Playgroud)

这个函数从mongoDB获取数据.

    SqlDataReader dr = SqlHelper.ExecuteReader("Select Top(12222)* From NewsFeed");
    string eventJson = new JavaScriptSerializer().Serialize(dr);
Run Code Online (Sandbox Code Playgroud)

这来自SQL Server.

我试图测量每个人的执行时间,结果是:
Mongo:172ms
SQL:185ms.
但是我知道mongoDB应该比SQL快得多,对吧!?!

c# linq performance mongodb

2
推荐指数
1
解决办法
2075
查看次数

如何暂时禁用滚动?

我正在使用scrollTo jQuery插件,并想知道是否有可能通过Javascript临时禁用滚动窗口元素?我想要禁用滚动的原因是当你滚动时scrollTo是动画,它变得非常丑陋;)

当然,我可以做一个$("body").css("overflow", "hidden");然后在动画停止时将其恢复为自动,但如果滚动条仍然可见但不活动会更好.

javascript jquery scroll

412
推荐指数
14
解决办法
67万
查看次数

处理数据库完整性

我正在使用innodb约束在我的应用程序的下一个版本中引入数据库完整性.一切顺利,但我的一些表有记录与删除的引用(死记录),因为他们我不能添加约束到表.

我在尝试:

ALTER TABLE `article` ADD FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`) ON DELETE CASCADE;
Run Code Online (Sandbox Code Playgroud)

我得到:

#1452 - Cannot add or update a child row: a foreign key constraint fails (`books`.&lt;result 2 when explaining filename '#sql-442_dc'&gt;, CONSTRAINT `#sql-442_dc_ibfk_1` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`) ON DELETE CASCADE)
Run Code Online (Sandbox Code Playgroud)

运行此查询,我发现超过500条记录没有引用(作者被删除,但他们的文章仍然存在):

SELECT `articles`.`id`
FROM `articles` LEFT JOIN `authors` ON `articles`.`author_id` = `authors`.`id`
WHERE ISNULL(`authors`.`id`);
Run Code Online (Sandbox Code Playgroud)

所以,在我添加约束之前,我必须处理这些约束.如何删除使用上述查询获得的所有记录?

我试过了:

DELETE FROM `articles` WHERE `id` IN (
  SELECT `articles`.`id`
  FROM `articles` LEFT JOIN `authors` ON `articles`.`author_id` …
Run Code Online (Sandbox Code Playgroud)

mysql innodb foreign-keys mysql-error-1093 mysql-error-1452

7
推荐指数
1
解决办法
2936
查看次数

使用`$`作为C/C++中的标识符是否安全?

$在C/C++中使用字符作为标识符的一部分是否安全?像这样,

int $a = 10;
struct $b;
class $c;

void $d();
Run Code Online (Sandbox Code Playgroud)

c c++ identifier special-characters

2
推荐指数
1
解决办法
181
查看次数

创建PHP类大纲

我正在寻找一个可以有效勾画一个类的函数或类:

class MyClass{

  /*
  * Perhaps include the function comments
  * in the function.
  */
  function mainFunction(){
    //Does Something
  } 

  function functionWithArgs($arg1,$arg2=false){
    //Does Something
    //The function I want will give e the arguments w/default values
  }

}
Run Code Online (Sandbox Code Playgroud)

是否有一个函数或库可以让我对这个类甚至文件的信息进行某种访问.

恩.

get_file_outline('fileWithAboveClass.php');

要么

get_class_outline('MyClass');

有没有人知道,或知道一种轻松写这个的方法?

php architecture class-design object outline

3
推荐指数
1
解决办法
261
查看次数

DLIB是一个很好的开源库,用于在C++中开发自己的机器学习算法吗?

DLIB是一个很好的开源库,用于在C++中开发自己的机器学习算法吗?

其他的如何,比如libSVM,SHOGUN?

c++ machine-learning data-mining dlib

6
推荐指数
1
解决办法
1993
查看次数

函数中的 return 语句作为类

我对充当类的函数中的 return 语句感到困惑。请参阅下面的示例代码:

<html>
<body>

<script type="text/javascript">
function test() {
    this.abc = 'def';
    return 3;
}

var mytest = new test(); 

document.write(mytest + ', ' + (typeof mytest) + ', ' + mytest.abc);

</script>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

代码输出:[object Object], object, def。

这是我的问题。我在 test() 函数中写了“return 3”。调用“new test()”时是否会忽略此语句?

谢谢。

javascript

4
推荐指数
1
解决办法
2万
查看次数

Rails 3,仅比较rails中两个日期时间列的日期

假设我想比较1条记录中两个日期时间列的日期.所以我不想看时间.

Viewed_date和updated_at(我添加了Viewed_date)是两种日期时间格式,但我只想看看它们是在相同的一天或几天发生的.datetime的问题在于它比较时间,这对我来说太具体了.

谢谢

-Elliot

ruby ruby-on-rails ruby-on-rails-3

5
推荐指数
1
解决办法
2867
查看次数

Android访问属性参考

在Android资源xml中引用主题属性的值,您使用问号(?)而不是(@).如下面的ListViewCustomStyle:

 <ListView 
     android:id="@+id/MainScreenListView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"
     style="?ListViewCustomStyle"/>
Run Code Online (Sandbox Code Playgroud)

如何在代码中使用ListViewCustomStyle的值?如果我以正常的方式尝试,即

com.myapp.R.attr.ListViewCustomStyle
Run Code Online (Sandbox Code Playgroud)

然后代码崩溃了.是否有一种特殊的方式来访问它,因为它是对项目的引用而不是实际项目?

android

2
推荐指数
1
解决办法
1197
查看次数

获取远程地址/ IP - C Berkeley套接字

如果我连接了套接字文件描述符(通过connect或bind),键入SOCK_STREAM,是否可以获取远程地址/ IP地址?

我需要在一个函数中执行此操作,其中除了套接字文件描述符之外没有任何其他数据.

c++ sockets ip-address berkeley-sockets

4
推荐指数
1
解决办法
3061
查看次数