The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Serialization exception for a collection created by selecting a subset of columns - {"Column 'CustomerID' does not belong to table Orders."}

Last post 11-18-2007, 9:49 AM by Mike.Griffin. 3 replies.
Sort Posts: Previous Next
  •  11-17-2007, 10:35 PM 6666

    Serialization exception for a collection created by selecting a subset of columns - {"Column 'CustomerID' does not belong to table Orders."}

     I use 2007.1.1112.0 and an attempt to serialize a collection with a select list that contains just a few columns fails:

      168             OrdersQuery ordersQuery = new OrdersQuery();

      169             ordersQuery.Select(ordersQuery.OrderID, ordersQuery.ShipAddress);

      170             OrdersCollection orders = new OrdersCollection();

      171             orders.Load(ordersQuery);

      172 

      173             XmlSerializer serializer = new XmlSerializer(typeof(OrdersCollectionProxyStub));

      174             StringBuilder builder = new StringBuilder();

      175             StringWriter writer = new StringWriter(builder);

      176             serializer.Serialize(writer, new OrdersCollectionProxyStub(orders));

     

    I'm not sure if it supposed to be this way, but I think it would be nice to put a note somewhere that you have to ask for all columns in order for your data being serializable.

     

    Thank you,

    Leonid

  •  11-18-2007, 3:34 AM 6668 in reply to 6666

    Re: Serialization exception for a collection created by selecting a subset of columns - {"Column 'CustomerID' does not belong to table Orders."}

    This is the 2nd time of late this issue has come up of late, though not in relation to serialization, here is the issue.

    Our low-level get methods look like this:

     

    Code:
    protected System.Int16? GetSystemInt16(string columnName)
    {
    if (this.row == null) this.AddNew();

    object o = this.row[columnName];
    return (o == DBNull.Value) ? null : (System.Int16?)o;
    }
     

    Notice, they don't check the Columns collection to make sure "columnName" exists, EntitySpaces has always been this way for performance, it's usually not a problem. If you don't bring back a column don't access it, however, serialization blindly accesses all of the properties. In order to fix it we would have to do something like this:

     

    Code:
    protected System.Int16? GetSystemInt16(string columnName)
    {
    if (this.row == null) this.AddNew();

    if (this.row.Table.Columns.Contains(columnName))
    {
    object o = this.row[columnName];
    return (o == DBNull.Value) ? null : (System.Int16?)o;
    }
    else
    {
    return null;
    }
    }

     

    The issue was/is we didn't want to have to ask if the column existed every time we were about to access it. We are going to do some performance analysis and come up with the proper solution for our mid December maintenance release. Unfortunately it wont make it into our official v1119 release.


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  11-18-2007, 9:26 AM 6673 in reply to 6668

    Re: Serialization exception for a collection created by selecting a subset of columns - {"Column 'CustomerID' does not belong to table Orders."}

    This is not urgent, at least for me :)

    Just an idea, though. As I understand, when a collection gets loaded, the framework first creates columns in the underlying data table based on what comes from the database. If at this point also create columns from the generated metadata, then the datatable would have both columns, from the database and from meta (excluding duplicates that should be skipped). Only columns that came from the database would have data, others will be empty (a potential problem here for null columns...). Then the GetSystemInt() won't worry about the column's existence - it's always there, but could be empty.

    Sorry if this does not make sense, I may not be familiar enough with the framework to make such assumptions.

    Thank you,

    Leonid 

  •  11-18-2007, 9:49 AM 6675 in reply to 6673

    Re: Serialization exception for a collection created by selecting a subset of columns - {"Column 'CustomerID' does not belong to table Orders."}

    Yes, that makes perfect sense and we will attack it from that perspective, good suggestion.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
View as RSS news feed in XML