Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Technology Research of Entity Framework2 #6

Closed
daisukenishino opened this issue Nov 7, 2014 · 1 comment
Closed

Technology Research of Entity Framework2 #6

daisukenishino opened this issue Nov 7, 2014 · 1 comment

Comments

@daisukenishino
Copy link
Contributor

Questions about EntityFramework

We have a variety of questions about EntityFramework.
We will request an investigation of the following questions to you.

Memory usage

We believe that EntityFramework behave as follows.

  • DbContext.xxxx() (xxxx is the table name)
    • If you call the above method, to hold all of the records in the table on the memory.
    • It is unclear to get at any stage. (When the DbContext generation? When the table access ?)
  • DbContext.Database.SqlQuery("...SQL statement...")
    • I have thought that result set of the SQL statement is hold on the memory.

Updating with ExecuteSqlCommand

  • If you use this method, you can freely run the SQL statement. However, SQL statements can be executed regardless of the contents of the entity. Therefore, I think that contents of the entity and database do not match after execution of this method.
  • If it is the behavior as described above, there is a need to refresh the contents of the entities?

Connection / Transaction management of SaveChanges method

  • Behavior of SaveChanges is as follows
    • Open the connection.
    • Start a transaction.
    • Perform a query (*1).
    • Finishe the transaction
    • Successful completion ... commit
    • Abnormal termination (exception) ... roll back
    • Close the connection
    • [Reference] Entity Framework - Try to check the transaction in the log output(ログ出力でトランザクションを確認してみる)
      http://ichiroku11.hatenablog.jp/entry/2014/04/16/232004
  • For matter of "* 1", when you look at the code of the Entity Framework from the following URL, each time entry.AcceptChanges method is executed against a record of change in a foreach in the AcceptAllChanges method.
  • For this reason, Entity Framework so that is doing the update instruction from the program for each of changed records. Round-trip between the APServer and DBServer occurs in such a processing method. Therefore, I think about the performance of problem occurs in the batch processing of large amounts of data processing.
  • Since the connection / transaction is created every time you call the SaveChanges method, Following (a) and (b) to use a different connection / another transaction. If you want to explicitly manage transactions, it is written the way to "treat as a single transaction(1つのトランザクションとして扱う)" in the above-referenced site.
    • Correct the Entity call the SaveChanges method (a)
    • Correct the Entity call the SaveChanges method (b)
  • For this reason, I think that it may dispense with as much as possible a single call to SaveChanges method. However, in the following case I think that there is a need to manage the explicit connection / transaction.
    • If you need to call more than once SaveChanges method.
    • When used in combination the SaveChanges method and ExecuteSqlCommand methods.
    • When used in combination the SaveChanges method and stored procedures.

There is something like a Better use in Entity Data Model how to make?

For example, either "divide the Entity Data Model in arbitrary units" or "entities combine into a single Entity Data Model".

  • If you wrap the Entity to one of the Entity Data Model, it is easy to combine multiple entity update to the call of a single SaveChanges method.
  • If you divide the Entity multiple of Entity Data Model, there is a need to call multiple times SaveChanges method. Therefore connection / transaction explicit management is required.
daisukenishino2 added a commit that referenced this issue Jun 2, 2015
daisukenishino added a commit that referenced this issue Jun 12, 2015
Merge pull request #6(SymphonyTeleca/SampleProgram/SignalRChat) was rolled back.
@daisukenishino
Copy link
Contributor Author

We summarized research results as follows(written by Japanese).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant