[CLOSED] Binding List(of Object) Parsing properties

  1. #1

    [CLOSED] Binding List(of Object) Parsing properties

    Consider the following object:

    Class Order {
    public int ID 
    public string Description
    public string OtherDescription
    }
    If I create a List(of Order) and then bind it to the following store

     <ext:Store runat="server" ID="OrderStore" DataSourceID="">
       <Reader>
          <ext:JsonReader ReaderID="ID">
            <Fields>
              <ext:RecordField Name="ID"/>
              <ext:RecordField Name="Description" />
            </Fields>
          </ext:JsonReader>
        </Reader>
      </ext:Store>
    When I bind this to a grid it seems to parse all properties even though they are not needed in the store, so my property OtherDescription, which is not used of referenced anywhere gets queried and causes multiple hits on the database.

    Is there a way to stop this?
  2. #2

    RE: [CLOSED] Binding List(of Object) Parsing properties

    Hi,

    The Store doesn't read property value if property is not in field collection (but read if you use SerializationMode="Complex", default mode is Simple)

    I wrote small sample which shows that the store doesn't read unrequired property (I added show alert in getter of OtherDescription property, also you cann add breakpoint to getter to ensure that store doesn't read that property).

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic"%>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Test Page</title>
        
        <script runat="server">
            public class Order 
            {
                public int ID
                { 
                    get; set;
                } 
                
                public string Description
                { 
                    get; set;
                }
    
                private string oDescription;
                public string OtherDescription
                {
                    get
                    {
                        Ext.Msg.Alert("Get", this.ID.ToString()).Show();
                        return this.oDescription;
                    }
                    set
                    {
                        this.oDescription = value;
                    }
                }
            }
            
            
            protected void Page_Load(object sender, EventArgs e)
            {
                OrderStore.DataSource = new List<Order>
                                            {
                                                new Order{ID = 1, Description = "Desc1", OtherDescription = "ODesc1"},
                                                new Order{ID = 2, Description = "Desc2", OtherDescription = "ODesc2"},
                                                new Order{ID = 3, Description = "Desc3", OtherDescription = "ODesc3"},
                                                new Order{ID = 4, Description = "Desc4", OtherDescription = "ODesc4"},
                                                new Order{ID = 5, Description = "Desc5", OtherDescription = "ODesc5"}
                                            };
                
                OrderStore.DataBind();
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="SM1" runat="server" />
            
            <ext:Store runat="server" ID="OrderStore">
               <Reader>
                  <ext:JsonReader ReaderID="ID">
                    <Fields>
                      <ext:RecordField Name="ID"/>
                      <ext:RecordField Name="Description" />
                    </Fields>
                  </ext:JsonReader>
                </Reader>
            </ext:Store>
            
            <ext:GridPanel runat="server" Width="600" Height="300" Title="Grid" StoreID="OrderStore">
                <ColumnModel>
                    <Columns>
                        <ext:Column Header="ID" DataIndex="ID"></ext:Column>
                        <ext:Column Header="Description" DataIndex="Description"></ext:Column>
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>
  3. #3

    RE: [CLOSED] Binding List(of Object) Parsing properties

    vladimir (7/23/2009)Hi,

    The Store doesn't read property value if property is not in field collection (but read if you use SerializationMode="Complex", default mode is Simple)
    Thanks, that explains it as I am using Complex. Luckily in this instance I can change my object to operate under simple but I am sure I might come accross this issue again and might not be able to change it to simple, is there a way around this or is this just the way it is designed to work?

    Cheers
  4. #4

    RE: [CLOSED] Binding List(of Object) Parsing properties

    Hi,

    Complex serialization serialize all object (even the property doesn't placed in field collection). There are two option which can help you


    1. Add Newtonsoft.Json.JsonIgnoreAttribute for properties which should be ignored during Complex serialization (but unfortunatelly you can't change business objects in some cases (project policy or something else))


    2. You can use Simple serialization with Complex for particular fields. Just add IsComplex="true" for field and will be used Simple serilization (which don't read unrequired field) but fields which marked as IsComplex will be serialized as complex

Similar Threads

  1. fill my store from a list of object.
    By DEV_EXT_TN in forum 2.x Help
    Replies: 0
    Last Post: Aug 01, 2012, 11:54 AM
  2. How to change List<object> to SqlDataSource
    By Aod47 in forum 1.x Help
    Replies: 0
    Last Post: May 25, 2012, 2:16 AM
  3. Replies: 0
    Last Post: Oct 21, 2011, 3:04 AM
  4. Replies: 4
    Last Post: Feb 02, 2010, 1:00 PM
  5. Binding Store to nested properties
    By r_honey in forum 1.x Help
    Replies: 2
    Last Post: Mar 02, 2009, 2:25 PM

Posting Permissions