Fast Serialization with Custom Properties

Posts   
 
    
jataylor
User
Posts: 13
Joined: 14-Feb-2007
# Posted on: 17-Oct-2008 16:48:04   

I have just upgraded to 2.6 and I am using the new Fast Serialization option. Everything is working fine except for 1 entity. We have some custom code on this entity that adds properties to the object. Before using Fast Serialization the code worked fine. We have code in the constructor to add the custom properties to the SerializationInfo object but it does not appear the Fast Serialization uses this method anymore.

How do you add custom properties where Fast Serialization will serialize and deserialize the data?

jataylor
User
Posts: 13
Joined: 14-Feb-2007
# Posted on: 17-Oct-2008 20:07:40   

Update: I discovered that when using fast serialization the ctor with the serializationInfo parameter is not being used or the GetObjectData Method does not get used.

If I turn off the fast serialization option off everything works fine. I still do not have an answer but I hope this update will help explain my problem better.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Oct-2008 22:48:08   

Are you doing that this way(Custom Member serialization/deserialization)?

Also please check this thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=11465

David Elizondo | LLBLGen Support Team
jataylor
User
Posts: 13
Joined: 14-Feb-2007
# Posted on: 17-Oct-2008 23:23:49   

Thanks for the post but the 2 links work with xml serialization. Let me show some code here explain what I am doing.

I am using Adapter Pattern, I have added code to the constructor that uses the SerializationInfo object.


protected BenefitEntity(SerializationInfo info, StreamingContext context) : base(info, context) { if(SerializationHelper.Optimization != SerializationOptimization.Fast) { batchCommission = (EntityCollection<BatchCommissionEntity>)info.GetValue("_batchCommission", typeof(EntityCollection<BatchCommissionEntity>)); benefit = (EntityCollection<BenefitEntity>)info.GetValue("_benefit", typeof(EntityCollection<BenefitEntity>)); _benefitCriteria = (EntityCollection<BenefitCriteriaEntity>)info.GetValue("_benefitCriteria", typeof(EntityCollection<BenefitCriteriaEntity>)); _benefitFee = (EntityCollection<BenefitFeeEntity>)info.GetValue("_benefitFee", typeof(EntityCollection<BenefitFeeEntity>)); _benefitGroupBenefit = (EntityCollection<BenefitGroupBenefitEntity>)info.GetValue("_benefitGroupBenefit", typeof(EntityCollection<BenefitGroupBenefitEntity>)); _benType = (EntityCollection<BenTypeEntity>)info.GetValue("_benType", typeof(EntityCollection<BenTypeEntity>)); _commRate = (EntityCollection<CommRateEntity>)info.GetValue("_commRate", typeof(EntityCollection<CommRateEntity>)); _enrollBenefit = (EntityCollection<EnrollBenefitEntity>)info.GetValue("_enrollBenefit", typeof(EntityCollection<EnrollBenefitEntity>)); _groupPlanBenefit = (EntityCollection<GroupPlanBenefitEntity>)info.GetValue("_groupPlanBenefit", typeof(EntityCollection<GroupPlanBenefitEntity>)); _groupPlanOption = (EntityCollection<GroupPlanOptionEntity>)info.GetValue("_groupPlanOption", typeof(EntityCollection<GroupPlanOptionEntity>)); _groupPlanRateBenefit = (EntityCollection<GroupPlanRateBenefitEntity>)info.GetValue("_groupPlanRateBenefit", typeof(EntityCollection<GroupPlanRateBenefitEntity>)); _groupVendorDistRule = (EntityCollection<GroupVendorDistRuleEntity>)info.GetValue("_groupVendorDistRule", typeof(EntityCollection<GroupVendorDistRuleEntity>)); _productBenefit = (EntityCollection<ProductBenefitEntity>)info.GetValue("_productBenefit", typeof(EntityCollection<ProductBenefitEntity>)); _underwriting = (EntityCollection<UnderwritingEntity>)info.GetValue("_underwriting", typeof(EntityCollection<UnderwritingEntity>)); _vendorDistRule = (EntityCollection<VendorDistRuleEntity>)info.GetValue("_vendorDistRule", typeof(EntityCollection<VendorDistRuleEntity>)); _batchCollectionViaBatchCommission = (EntityCollection<BatchEntity>)info.GetValue("_batchCollectionViaBatchCommission", typeof(EntityCollection<BatchEntity>)); _benefitCriteriaCollectionViaGroupPlanOption = (EntityCollection<BenefitCriteriaEntity>)info.GetValue("_benefitCriteriaCollectionViaGroupPlanOption", typeof(EntityCollection<BenefitCriteriaEntity>)); _benefitGroupCollectionViaBenefitGroupBenefit = (EntityCollection<BenefitGroupEntity>)info.GetValue("_benefitGroupCollectionViaBenefitGroupBenefit", typeof(EntityCollection<BenefitGroupEntity>)); _brokerCollectionViaCommRate = (EntityCollection<BrokerEntity>)info.GetValue("_brokerCollectionViaCommRate", typeof(EntityCollection<BrokerEntity>)); _brokerTreeCollectionViaBatchCommission = (EntityCollection<BrokerTreeEntity>)info.GetValue("_brokerTreeCollectionViaBatchCommission", typeof(EntityCollection<BrokerTreeEntity>)); _carrierCollectionViaCommRate = (EntityCollection<CarrierEntity>)info.GetValue("_carrierCollectionViaCommRate", typeof(EntityCollection<CarrierEntity>)); _carrierCollectionViaBenefit = (EntityCollection<CarrierEntity>)info.GetValue("_carrierCollectionViaBenefit", typeof(EntityCollection<CarrierEntity>)); _carrierBrokerCollectionViaCommRate = (EntityCollection<CarrierBrokerEntity>)info.GetValue("_carrierBrokerCollectionViaCommRate", typeof(EntityCollection<CarrierBrokerEntity>)); _categoryCollectionViaProductBenefit = (EntityCollection<CategoryEntity>)info.GetValue("_categoryCollectionViaProductBenefit", typeof(EntityCollection<CategoryEntity>)); _commTierCollectionViaCommRate = (EntityCollection<CommTierEntity>)info.GetValue("_commTierCollectionViaCommRate", typeof(EntityCollection<CommTierEntity>)); _commTierCollectionViaBatchCommission = (EntityCollection<CommTierEntity>)info.GetValue("_commTierCollectionViaBatchCommission", typeof(EntityCollection<CommTierEntity>)); _covCodeCollectionViaGroupPlanRateBenefit = (EntityCollection<CovCodeEntity>)info.GetValue("_covCodeCollectionViaGroupPlanRateBenefit", typeof(EntityCollection<CovCodeEntity>)); _criteriaCollectionViaBenefitCriteria = (EntityCollection<CriteriaEntity>)info.GetValue("_criteriaCollectionViaBenefitCriteria", typeof(EntityCollection<CriteriaEntity>)); _criteriaCollectionViaGroupPlanOption = (EntityCollection<CriteriaEntity>)info.GetValue("_criteriaCollectionViaGroupPlanOption", typeof(EntityCollection<CriteriaEntity>)); _enrollMasterCollectionViaUnderwriting = (EntityCollection<EnrollMasterEntity>)info.GetValue("_enrollMasterCollectionViaUnderwriting", typeof(EntityCollection<EnrollMasterEntity>)); _enrollMasterCollectionViaEnrollBenefit = (EntityCollection<EnrollMasterEntity>)info.GetValue("_enrollMasterCollectionViaEnrollBenefit", typeof(EntityCollection<EnrollMasterEntity>)); _enrollPolicyCollectionViaEnrollBenefit = (EntityCollection<EnrollPolicyEntity>)info.GetValue("_enrollPolicyCollectionViaEnrollBenefit", typeof(EntityCollection<EnrollPolicyEntity>)); _feeCollectionViaBenefitFee = (EntityCollection<FeeEntity>)info.GetValue("_feeCollectionViaBenefitFee", typeof(EntityCollection<FeeEntity>)); _groupMasterCollectionViaGroupVendorDistRule = (EntityCollection<GroupMasterEntity>)info.GetValue("_groupMasterCollectionViaGroupVendorDistRule", typeof(EntityCollection<GroupMasterEntity>)); _groupMasterCollectionViaCommRate = (EntityCollection<GroupMasterEntity>)info.GetValue("_groupMasterCollectionViaCommRate", typeof(EntityCollection<GroupMasterEntity>)); _groupPlanCollectionViaGroupPlanOption = (EntityCollection<GroupPlanEntity>)info.GetValue("_groupPlanCollectionViaGroupPlanOption", typeof(EntityCollection<GroupPlanEntity>)); _groupPlanCollectionViaGroupPlanBenefit = (EntityCollection<GroupPlanEntity>)info.GetValue("_groupPlanCollectionViaGroupPlanBenefit", typeof(EntityCollection<GroupPlanEntity>)); _groupPlanBenefitCollectionViaGroupPlanOption = (EntityCollection<GroupPlanBenefitEntity>)info.GetValue("_groupPlanBenefitCollectionViaGroupPlanOption", typeof(EntityCollection<GroupPlanBenefitEntity>)); _groupPlanRateCollectionViaGroupPlanRateBenefit = (EntityCollection<GroupPlanRateEntity>)info.GetValue("_groupPlanRateCollectionViaGroupPlanRateBenefit", typeof(EntityCollection<GroupPlanRateEntity>)); _groupPlanRateBenefitCollectionViaEnrollBenefit = (EntityCollection<GroupPlanRateBenefitEntity>)info.GetValue("_groupPlanRateBenefitCollectionViaEnrollBenefit", typeof(EntityCollection<GroupPlanRateBenefitEntity>)); _personCollectionViaUnderwriting = (EntityCollection<PersonEntity>)info.GetValue("_personCollectionViaUnderwriting", typeof(EntityCollection<PersonEntity>)); _productCollectionViaBenType = (EntityCollection<ProductEntity>)info.GetValue("_productCollectionViaBenType", typeof(EntityCollection<ProductEntity>)); _productCollectionViaProductBenefit = (EntityCollection<ProductEntity>)info.GetValue("_productCollectionViaProductBenefit", typeof(EntityCollection<ProductEntity>)); _productCollectionViaCommRate = (EntityCollection<ProductEntity>)info.GetValue("_productCollectionViaCommRate", typeof(EntityCollection<ProductEntity>)); _productTypeCollectionViaProductBenefit = (EntityCollection<ProductTypeEntity>)info.GetValue("_productTypeCollectionViaProductBenefit", typeof(EntityCollection<ProductTypeEntity>)); _stateCollectionViaCommRate = (EntityCollection<StateEntity>)info.GetValue("_stateCollectionViaCommRate", typeof(EntityCollection<StateEntity>)); _vendorCollectionViaVendorDistRule = (EntityCollection<VendorEntity>)info.GetValue("_vendorCollectionViaVendorDistRule", typeof(EntityCollection<VendorEntity>)); _vendorCollectionViaGroupVendorDistRule = (EntityCollection<VendorEntity>)info.GetValue("_vendorCollectionViaGroupVendorDistRule", typeof(EntityCollection<VendorEntity>)); _benefit = (BenefitEntity)info.GetValue("_benefit", typeof(BenefitEntity)); if(_benefit!=null) { _benefit.AfterSave+=new EventHandler(OnEntityAfterSave); } _carrier = (CarrierEntity)info.GetValue("_carrier", typeof(CarrierEntity)); if(_carrier!=null) { _carrier.AfterSave+=new EventHandler(OnEntityAfterSave); }

            base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance());
        }

        // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
        ratingCriteria = (System.Collections.Hashtable)info.GetValue("ratingCriteria", typeof(System.Collections.Hashtable));
        discountCriteria = (System.Collections.Hashtable)info.GetValue("discountCriteria", typeof(System.Collections.Hashtable));
        isRated = info.GetBoolean("isRated");
        rate = info.GetDecimal("rate");
        discountRate = info.GetDecimal("discountRate");
        rateId = info.GetInt32("rateId");
        ratingState = info.GetString("ratingState");
        // __LLBLGENPRO_USER_CODE_REGION_END

}

Note in the code region i populate the local vars with the data from the serialized data. I also have code in the GetObject method that populates the serializationInfo during deserialization. This code works fine when you do not use the Fast Serialization. When using the fast serialization it does not call the constructor or the getobjectdata.

So i am needing an example of how to add members to the serialization data that is used with using the FastSerializationMethod.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 18-Oct-2008 10:55:14   
Frans Bouma | Lead developer LLBLGen Pro
jataylor
User
Posts: 13
Joined: 14-Feb-2007
# Posted on: 18-Oct-2008 17:40:04   

Found it this time. Thanks so Much.... Just to document in this thread the change below is the comparision between the old way and the new way of adding custom data to seraialization. I will make the change now. I will post my results later.

old serialize method protected override void OnGetObjectData(SerializationInfo info, StreamingContext context) { info.Add("_orderTotal", _orderTotal); }

new deserialize method (Fast Serialization) protected override void SerializeOwnedData(SerializationWriter writer, object context) { base.SerializeOwnedData(writer, context); writer.WriteOptimized(_orderTotal); }

old deserialize method protected override void OnDeserialized(SerializationInfo info, StreamingContext context) { _orderTotal = info.GetDecimal("_orderTotal"); }

new deserialice method protected override void DeserializeOwnedData(SerializationReader reader, object context) { base.DeserializeOwnedData(reader, context); _orderDecimal = reader.ReadOptimizedDecimal(); }

jataylor
User
Posts: 13
Joined: 14-Feb-2007
# Posted on: 18-Oct-2008 21:52:54   

It works again. Thanks for your help.