Pregunta

Yo solía prender a todos los GridViews, etc. DetailViews en mi página usando un ObjectDataSource (a menos que no era posible hacerlo). Recientemente, he comenzado vinculante todos mis contols programáticamente. Me parece mucho más limpio y más fácil, aunque algunos pueden estar en desacuerdo.

La unión con un ObjectDataSource obviamente tiene sus ventajas y desventajas, al igual que lo hace mediante programación.

Say I se unen a un GridView mediante programación (por ejemplo GridView1.DataSource = SomeList), cuando cambio de página en la GridView, tengo que también código esto. Cada vez que cambia la página que tiene que GridView1.DataSource = SomeList llamada de nuevo. Obviamente, con un ObjectDataSource No necesito hacer esto. Normalmente me quedo mi objetivo SomeList en el ViewState así que cuando me cambio de página que no necesito para golpear la base de datos cada vez.

Mi pregunta es: ¿Es esta la forma en que funciona el ObjectDataSource? Tampoco la almacena de datos en el ViewState y no golpea la base de datos de nuevo a menos de llamar al método .Select? Me gusta tratar de obtener el mejor rendimiento de mis aplicaciones y golpear la base de datos el menor número de veces posible, pero realmente no me gusta la idea de almacenar una enorme lista en el ViewState. ¿Hay una mejor manera de hacer esto? Es el almacenamiento en caché por usuario una idea buena (o posible)? ¿Me acaba de golpear la base de datos cada vez de almacenar mi lista enorme en el ViewState? ¿Es a veces mejor para golpear la base de datos que utilizar ViewState?

¿Fue útil?

Solución

Does it store it's data in the ViewState and not hit the database again unless you call the .Select method?

No its not save the data in ViewState. In the view state gridview and other similar lists, saves the General Status, eg the sort column, the page, the total pages, the control state, but not the Data.

Is caching per user a good idea

The caching per user on server side is not so good idea except if the caching is last for few minutes only or/and the data that you going to cache is very small. If you cache per user large amount of data for long time they going to grow too much especial if a user starts to read a lot of pages, that at the end you have the same problem.

Now you have to show a large amount of data that come from the relation of many tables, then maybe is better to cache the full relation of the tables to "one flat table".

Shall I just hit the database everytime instead of storing my huge list in the ViewState?

This is also depend from how fast you have design the reading of your data. For me is better to keep the ViewState small, and keep there only informations that you need to make the actions on your page, and not data.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top