EF6 code first: How to load DbCompiledModel from EDMX file on startup?

天涯浪子 提交于 2019-12-05 02:59:47
Mikael Eliasson

I tested if I could get it to work by serializing the DbCompiledModel.

Both getting it from EF and providing it when building a new context works. The problem is that everything is private so it will not serialize anything.

If you can get the serializer you use to serialize private members it should be quite simple.

1) In the end of OnModelCreating (if you are using code first) you can do

modelBuilder.Build().Compile()

Slightly simplified as you should provide some arguments

2) Serialize that one. For work with private members try looking at JSON.Net: Force serialization of all private fields and all fields in sub-classes or try to use the BinaryFormatter Why is the BinaryFormatter serializing private members and not the XMLSerializer or the SoapFormatter ?

3) Save that to disk

4) Read the file from disk and Deserialize it to a new DbCompiledModel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!