If I Query a SQL Server VarBinary(MAX) Column, Will the Entire File be Loaded In Memory?

sc4hvdpw  于 2023-08-02  发布在  SQL Server
关注(0)|答案(1)|浏览(88)

My application is using SQL Server 2008 and we need to add functionality for users to optionally be able to save any file of any size to a database table. I have set up the table similar to this format:

  • FileStorageID - int (indentity PK) (This is also a foreign key to a different table)
  • FileData - varbinary(max)
  • FileName - varchar(1000)

The FileStorage table has a zero-to-one relationship to another table Documentation . The idea is that users can write either write some text, upload a file, or both.

This table looks as follows:

  • DocumentationID - int (identity PK , FK to an "IrrelevantInterestingObject" table)
  • Text - varchar(max)
  • FileStorageID - int (FK to aforementioned FileStorage table)

My question is this: When I query the Documentation table using Entity Framework 5, and a file is present in the database, will the entire file be stored in memory? If yes, what would a reasonable threshold be before there is a noticeable performance issue?

btxsgosb

btxsgosb1#

If you query Documentation table no data from related FileStorage table will be loaded until you load the relation either through eager, explicit or lazy loading. Once you use any such method or query FileStorage directly whole FileData for every retrieved record will be loaded to memory.

相关问题