1

开发网站(使用实体框架)我遇到了以下问题:

1.如果很多人(比如说10,000人)试图通过实体框架同时“写入”到数据库(SQL Server)中的同一个特定表,会发生什么?

2.在我的项目中,我有模块,出于解耦原因,我使用单例类(ModulesManager),它应该从每个模块中采取行动并异步执行,如下所示:

    public void InsertNewRecord(Action addNewRecordAction)
    {
        if (addNewRecordAction != null)
        {
            addNewRecordAction.BeginInvoke(recordCallback, null);
        }
    }

使用单例类作为唯一负责写入 DB 的地方是一种好方法吗?

3.Entity Framework能提供与使用SQL查询相同的速度吗?

4

1 回答 1

0

如果很多人(比如说 10,000 人)试图通过实体框架同时“写入”到 DB(SQL Server)中的同一个特定表,会发生什么?

If you mean inserting to the same table those insert will be processed based on transaction isolation level in the database. Usually only single transaction can hold a lock for insertion so inserts are processed in sequence (it has nothing to do with EF). Having 10.000 users concurrently inserting doesn't seem like sustainable architecture - some of them may timeout.

In my project i have modules and for decoupling reasons i using singleton class (ModulesManager) which should take Action from each module and execute it asynchronous like following:

Your manager asynchronously invokes the action so the answer is mostly dependent on what the action is doing. If it opens its own context, performs some changes and saves them, you should not have any technical problem on EF side.

Does Entity Framework can provide same speed as using SQL queries ?

不会。EF 会进行额外的处理,因此它总是会变慢。

于 2013-04-18T11:07:24.257 回答