How do I prevent Entity Framework from loading a FileStream column into a byte array?

前端 未结 1 2080
难免孤独
难免孤独 2021-02-14 08:24

I am developing a file storage application, and we have incorporated the FileStream type in our database. The system is expected to support large files. One portion of the app

1条回答
  •  情歌与酒
    2021-02-14 08:50

    Garrison, you can use a feature called "entity splitting" where you map two related entities to a single table. So in the first entity you would have all but the filestream property. In the 2nd entity you would have the primary key (same as in the first entity) and the filestream property. Create a one:one relationship between the entities in your model and then map both entities to the same table. Now the entity with the filestream is related and you can load or lazy load it as needed. The only downside is that it's not a property of your main entity, so you have to navigate to the related entity and then the property.

    myEntity.MyRelatedEntity.TheFileStreamProperty

    Here's an old blog post I wrote that shows how to do this in the EDM Designer.

    You can also achieve the same mapping with Code FIrst. Here's an MSDN article I wrote that contains an entity splitting article. http://msdn.microsoft.com/en-us/data/hh272551

    HTH Julie

    0 讨论(0)
提交回复
热议问题