[CLOSED] Store Question

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Store Question

    Hello,

    Wow, it's been a while but here I am.

    Consider the following class:

    class Customer {
      public Employer { get; set; }
      public Building { get; set; }
      public string Name { get; set; }
    }
    What if I wanted to bind this to a Store so that I can use "Employer.CompanyName" as a record field in a GridPanel without having to use SerializationMode complex?

    I don't want to use complex because I'm using lazy initialization on my Customer object and I don't want Hibernate to resolve Building (that would cost another hit to the database).

    I also don't want to use the Newton.JSON dll in my entity layer because it is a seperate layer.

    Any suggestions would be greatly appreciated.

    Cheers,
    Timothy
  2. #2

    RE: [CLOSED] Store Question

    Hi,

    We have added IsComplex property for RecordField. Now you can apply complex serialization for an individual field instead a whole DataSource.

    Please see the following sample
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Customer> list = new List<Customer>(5);
    
            for (int i = 1; i <= 5; i++)
            {
                Customer customer = new Customer
                                        {
                                            ID = i,
                                            FirstName = ("FirstName" + i),
                                            LastName = ("LastName" + i),
                                            Company = ("Company" + i)
                                        };
    
                Address address = new Address
                                      {
                                          StreetAddress = ("Street" + i), 
                                          City = ("City" + i)
                                      };
                
                customer.Address = address;
    
                list.Add(customer);
            }
    
            Store1.DataSource = list;
            Store1.DataBind();
        }
    
    
        public class Customer
        {
            public int ID { get; set; }
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string Company { get; set; }
            public Address Address { get; set; }
        }
    
        public class Address
        {
            public string StreetAddress { get; set; }
            public string City { get; set; }
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    
         <script type="text/javascript">
             function prepareCity(value, rec) {
                 return rec.Address.City;
             }
             
             function prepareStreet(value, rec) {
                 return rec.Address.StreetAddress;
             }
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
           <ext:Store runat="server" ID="Store1" AutoLoad="true">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="ID" Type="Int" />
                            <ext:RecordField Name="FirstName" />
                            <ext:RecordField Name="LastName" />
                            <ext:RecordField Name="Company" />
                            <ext:RecordField Name="Address" IsComplex="true"/>
                            <ext:RecordField Name="City">
                                <Convert Fn="prepareCity" />
                            </ext:RecordField>
                            <ext:RecordField Name="StreetAddress">
                                <Convert Fn="prepareStreet" />
                            </ext:RecordField>
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            
             <ext:GridPanel 
                ID="GridPanel1" 
                runat="server" 
                Title="Customers" 
                Height="300"
                StoreID="Store1">
                <ColumnModel ID="ColumnModel1" runat="server">
                <Columns>
                    <ext:Column Header="ID" DataIndex="ID" />
                    <ext:Column Header="FirstName" DataIndex="FirstName"  />
                    <ext:Column Header="LastName" DataIndex="LastName" />
                    <ext:Column Header="Company" DataIndex="Company" />            
                    <ext:Column Header="City" DataIndex="City" />            
                    <ext:Column Header="Street" DataIndex="StreetAddress" />            
                </Columns>
                </ColumnModel>
                <LoadMask ShowMask="true" />
            </ext:GridPanel> 
        </form>
    </body>
    </html>
  3. #3

    RE: [CLOSED] Store Question

    Thanks vlad,

    That is a really good addition I'll give it a go.

    Cheers,
    Timothy
  4. #4

    RE: [CLOSED] Store Question

    Hmm, as of revision 1488 I'm receiving the following:

    System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext() at Newtonsoft.Json.JsonSerializer.SerializeDictionary(JsonWriter writer, IDictionary values) at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter) at Newtonsoft.Json.JsonSerializer.WriteMemberInfoProperty(JsonWriter writer, Object value, JsonMemberMapping memberMapping) at Newtonsoft.Json.JsonSerializer.SerializeObject(JsonWriter writer, Object value) at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter) at Newtonsoft.Json.JsonSerializer.WriteMemberInfoProperty(JsonWriter writer, Object value, JsonMemberMapping memberMapping) at Newtonsoft.Json.JsonSerializer.SerializeObject(JsonWriter writer, Object value) at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter) at Newtonsoft.Json.JsonSerializer.WriteMemberInfoProperty(JsonWriter writer, Object value, JsonMemberMapping memberMapping) at Newtonsoft.Json.JsonSerializer.SerializeObject(JsonWriter writer, Object value) at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter) at Newtonsoft.Json.JsonSerializer.SerializeList(JsonWriter writer, IList values) at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter) at Newtonsoft.Json.JsonSerializer.WriteMemberInfoProperty(JsonWriter writer, Object value, JsonMemberMapping memberMapping) at Newtonsoft.Json.JsonSerializer.SerializeObject(JsonWriter writer, Object value) at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter) at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value) at Coolite.Ext.Web.JSON.Serialize(Object obj, List`1 converters, Boolean quoteName) at Coolite.Ext.Web.JSON.Serialize(Object obj) at Coolite.Ext.Web.StoreDataBound.PerformDataBinding(IEnumerable data) at Coolite.Ext.Web.StoreDataBound.OnSelect(IEnumerable data) at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) at Coolite.Ext.Web.StoreDataBound.PerformSelect() at Coolite.Ext.Web.StoreDataBound.DataBind() at Management_Administration_Shared_Users.Users_RefreshData(Object sender, StoreRefreshDataEventArgs e) in e:\XXX\Web\Management\Administration\Shared\Users.ascx.cs:line 76 at Coolite.Ext.Web.Store.OnRefreshData(StoreRefreshDataEventArgs e) at Coolite.Ext.Web.Store.RaiseAjaxPostBackEvent(String eventArgument)
    Would almost appear that you're running over one of my other properties called Responses which is the only collection on my User class. Here is my Store definition:

    <ext:Store ID="Users"
        runat="server"
        AutoLoad="true"
        IgnoreExtraFields="true"
        OnRefreshData="Users_RefreshData"
        RemoteSort="true">
        <AutoLoadParams>
            <ext:Parameter Name="start" Value="={0}" />
            <ext:Parameter Name="limit" Value="={15}" />
        </AutoLoadParams>
        <Proxy>
            <ext:DataSourceProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader ReaderID="Id">
                <Fields>
                    <ext:RecordField Name="Id" Type="Auto" />
                    <ext:RecordField Name="DisplayName" />
                    <ext:RecordField Name="LastName" />
                    <ext:RecordField Name="FirstName" />
                    <ext:RecordField Name="Username" />
                    <ext:RecordField Name="UserGroup" IsComplex="true" />
                    <ext:RecordField Name="Email" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <SortInfo Field="LastName" />
    </ext:Store>
  5. #5

    RE: [CLOSED] Store Question

    Yup, I changed the get of my Responses property on my User class to throw a NotImplementException and sure enough it is being touched which is invoking NHibernate to resolve the association.

    If I remove the IsComplex from the UserGroup RecordField it stops called Responses which is weird??

    Your advice would be very much appreciated!

    Cheers,
    Timothy
  6. #6

    RE: [CLOSED] Store Question

    Hi Timothy,

    Can you post example which reproduces the problem? I can't reproduce it
  7. #7

    RE: [CLOSED] Store Question

    Yeah, I'm struggling to get an example to work, I'm having to cut across 4 different layers and compact them into a simple example :(
  8. #8

    RE: [CLOSED] Store Question

    Hmm, OK might be a little interesting:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        
        public class Customer
        {
            public Address Address { get; set; }
    
            public string Name { get; set; }
    
            public IList<Address> Additional
            {
                get
                {
                    throw new NotImplementedException("Additional not implemented");
                }
                set
                {
                    throw new NotImplementedException("Additional not implemented");
                }
            }
        }
    
        public class Address
        {
            public string Street { get; set; }
            public Country Country
            {
                get
                {
                    throw new NotImplementedException("Country not implemented");
                }
                set
                {
                    throw new NotImplementedException("Country not implemented");
                }
            }
        }
        
        public class Country
        {
            public string Name { get; set; }    
        }
        
        protected void Store1_RefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            IList<Customer> Customers = new List<Customer>();
    
            Customers.Add(new Customer
            {
                Address = new Address
                {
                    Street = "Durward"
                },
                Name = "Timothy"
            } );
    
            Store1.DataSource = Customers;
            Store1.DataBind();
        }
        
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:Store runat="server" ID="Store1" AutoLoad="true" IgnoreExtraFields="true" OnRefreshData="Store1_RefreshData" RemoteSort="true">
                <Proxy>
                    <ext:DataSourceProxy />
                </Proxy>
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="Address" IsComplex="true" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
                <SortInfo Field="Name" />
            </ext:Store>
            <ext:GridPanel runat="server" 
                StoreID="Store1"
                Height="300">
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column DataIndex="Name" Header="Name" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel> 
        </form>
    </body>
    </html>
    Would appear that the IsComplex goes numerous levels deep, see how it crashes when it goes to resolve Country on the Address object?

    Cheers,
    Timothy
  9. #9

    RE: [CLOSED] Store Question

    Would be best if we could register a single field from the associated class instead of treating the entire object as complex, for instance:

    <ext:RecordField Name="Address.Street" />
    This would stop the object from resolving Country which calls the database again.

    Cheers,
    Timothy
  10. #10

    RE: [CLOSED] Store Question

    Hi Timothy,

    Just want to inform you that we are working on your request.
    We are working on server mapping ability. I mean that you will be able to set complex name


    <ext:RecordField Name="Address" ServerMapping="Person.Address"/>

    will use only Address property from Person (all other field from Person will not be used)
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Question about store
    By feanor91 in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 27, 2012, 11:49 AM
  2. A question about store
    By wxmayifei in forum 1.x Help
    Replies: 2
    Last Post: Oct 14, 2010, 8:35 AM
  3. [CLOSED] [1.0] Store Submit Question
    By ljankowski in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Aug 20, 2010, 3:38 PM
  4. a Store question
    By Adam in forum 1.x Help
    Replies: 1
    Last Post: Mar 30, 2010, 5:08 PM
  5. [CLOSED] Store Question
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Apr 03, 2009, 3:56 PM

Posting Permissions