If the goal is to maintain a list of recently used filters, I would serialize the complete FilterParams object in the XML / column field after binding the model. By storing it in an XML field, you also provide the flexibility of using XQuery and DML if you need a later version for a more focused request for information.
public ActionResult GetData(FilterParams filterParams) {
And then in your DataAccess class, you will need two methods: one for saving and one for retrieving filters:
public void SaveFilter(FilterParams filterParams){ var ser = new System.Xml.Serialization.XmlSerializer(typeof(FilterParams)); using (var stream = new StringWriter()) {
Then, when you want to get the saved filter, perhaps with Id:
public FilterParams GetFilter(int filterId){
Remember that your FilterParams class must have a default constructor (no parameters), and you can use the [XmlIgnore] attribute to prevent properties from being serialized to the database if you want.
public class FilterParams{ public string Name {get;set;} public string Age {get;set;} [XmlIgnore] public string PropertyYouDontWantToSerialise {get;set;} }
Note. SaveFilter returns Void, and for brevity, error handling is not required.
source share