How to save state across requests for an entity in ASP.NET without saving to database using EntityFramework?

后端 未结 3 994
眼角桃花
眼角桃花 2021-01-14 10:40

I\'m working on a CRUD ASP.NET WebForms web application consisting of a couple of pages in which the user fills in data. My client doesn\'t want to store the entities in the

相关标签:
3条回答
  • 2021-01-14 10:58

    You can store all objects used in the client application in the Session and then when the user clicks finish you send those objects to a service/method where you can convert them to entities and then submit them to the database.

    0 讨论(0)
  • 2021-01-14 10:59

    Use MemCached.
    there are tons of examples on the internet.
    Try this :
    Implementing Distributed Caching using Memcached

    0 讨论(0)
  • 2021-01-14 11:16

    Using ViewState is going to significantly increase the amount of data your sending down the wire, as all Viewstate data is serialised into a hidden input in the form, so as you add objects your HTTP request-response is going to grow significantly.

    There's no magic bullet in this really. If your data is not too complex I'd store the values in the query string. If your objects are getting complex and big and you want to maintain type safety I'd use Session, but remember to clean up after yourself!

    a further option is to use the MVC paradigm and store the values in the form it's self using hidden inputs. This means you don't need to worry about clearing up your session if the user bugs out half way though but it also keeps your querystring clean.

    think thats all your options, querystring, viewstate(don't do it), session or hidden variables.

    Ok so you have to seraialise your data, so you cannot persist the context. this is not serialiseable so the above are your options:

    they each have positive and negatives,

    • Viewstate (inefficent but easy to use)
    • Querystring (efficent but impractical for large data sets and editable)
    • Session(adds server load and needs cleaning up but allows you to persist data on the server only)
    • hidden variables(hidden from user but more efficient than viewstate requires a lot of hidden inputs for each property)

    Take your pick!

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