Breeze / breeze.server.net

Breeze support for .NET servers
MIT License
76 stars 62 forks source link

Metadata-only EFContextProvider #50

Closed randellhodges closed 7 years ago

randellhodges commented 7 years ago

I followed the instructions from: http://breeze.github.io/doc-js/metadata-with-ef.html

One thing I noticed is that the called to Metadata() hangs for 15 seconds (connection timeout) and then returns the data. I put in a fake connection string with a command timeout of 1 and it only hangs for about 1.6 seconds. Since I wrapped all this in a static, I only incur this penalty the first time.

I guess it probably isn't really a Breeze bug. I'm guessing it is more about the DbContext. Maybe there is something that can be done, maybe not?

I am using the .NET Core version with EF 6

steveschmitt commented 7 years ago

I've noticed that EF connects to the database to when we ask it for metadata. I assume it's to check for schema updates. I don't know how to turn that off.

randellhodges commented 7 years ago

I figured it would be an EF problem. Just putting this out there, more for documentation purposes.

This is the dummy connection string I'm using. The call to Metadata with it takes about 1.6 seconds. Again, if you do this in a static, or do it once and then just use the results in a static file, that solves the problem in production.

Data Source=(LocalDb)\v11.0;Initial Catalog=dummy;Integrated Security=True;Connection Timeout=1

marcelgood commented 7 years ago

Did you set the DB Initializer to null as in the example? Without that, EF will try to create the database.

Database.SetInitializer<NorthwindDtoContext>(null)

randellhodges commented 7 years ago

I did. It still hung for about 15 seconds. Using the dummy connection string cut it down to under 2 seconds.

randellhodges commented 7 years ago

I am going to close it because I don't really think this is a problem with Breeze itself.

I would suggest that, whenever you have time, a note in the documentation that describes this way of doing things can incur a heavy delay. Either don't do it at all in production, or do it once and hold the metadata in a static and return it in the Metadata method.