Purpose :
In this article we will identify
what is the best way to save different kind of views in database without making
any changes in database and base classes of view.This article includes 2 parts
,
In First part we will identify the
criteria and will design Tables for it. Part1
Second part contains the C# code for
classes required to implement in a generic way.
Recap what we did in Part1
In part1 we had designed database tables to store data into tables.
Part2
In this article, we have to create classes to save and fetch views in/from database.
as we know we are going to save data in XML form so there will be some utility(Serialization) that creates XML for us.
Serialization: It is process to convert an Object into XML/Binary.
Deserialization: It is a way convert XML data into Object.
Assuming we have to save different information for e.g. Grouping(includes to save information of column, and order), Filtering (includes columnName, Filterexpression),
Sorting(ColumnName,OrderType:Ascending/descending). And this information needed to be save as xml. So we have to create somthing like below as XML.
<XMLViewSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<lstSorting>
<Sorting>
<ColumnName>STN</ColumnName>
<SortingOrder>Ascending</SortingOrder>
<OrderNo>0</OrderNo>
</Sorting>
</lstSorting>
<lstFiltering>
<Filtering>
<ColumnName />
<FilterExpression />
<OrderNo>0</OrderNo>
</Filtering>
</lstFiltering>
<lstGrouping />
<lstPaging />
<lstFieldChooser />
</XMLViewSettings>
Sorting,Paging,FieldChooser,Filtering,Grouping
are the classes required to serialize. So set Classes as serilize and
properties as XMLElement.
|
Fig 1 | | | |
|
|
|
Now we can see in fig 1 there is a class diagram available for the classes required to store data and convert it to XML .
SerializationUtil<T>: Is a generic classes, if we want to create a classs with serialization support we can extend that class with SerializationUtil<T> and T is the type of Class needed to support.