AnantLabs / codesmith

Automatically exported from code.google.com/p/codesmith
1 stars 0 forks source link

CSLA - Generated Criteria objects don't work in Silverlight #398

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Generate any object (EditableRoot) and it's associated criteria object
2.  From Silverlight call one of the asynchronous factory methods, passing in a 
populated criteria object
3.

What is the expected output? What do you see instead?

If you put a breakpoint in your DataPortal_Fetch method, you will see that it 
called the method as if no criteria was passed.

What version of the product are you using?

CodeSmith: v5.2.1, CSLA Templates: v2.0.1.1656, CSLA Framework: v4.0.0.
VS 2010, CSLA 4 beta 2

Please provide any additional information below.

In my (limited) knowledge of CSLA and Silverlight, I believe that this is 
happening because of the following:

The Criteria objects cannot be serialized and sent over the wire, because they 
use a "backing" property.  The templates generate a Dictionary<string, object> 
called _bag that holds all of the criteria properties.  I believe that there 
are 2 possible solutions to this problem:

Solution 1 - When generating the templates, override the OnGetState and 
OnSetState methods so that the serializer can properly serialize the Criteria 
objects.  The code would look somewhat like the following:

 protected override void OnGetState(SerializationInfo info, StateMode mode)
        {
            base.OnGetState(info, mode);
            info.AddValue("_someIntProperty", GetValue<System.Int32>("SomeIntProperty"));
            info.AddValue("_someStringProperty", GetValue<System.String>("SomeStringProperty"));
        }

        protected override void OnSetState(SerializationInfo info, StateMode mode)
        {
            base.OnSetState(info, mode);
            _bag["SomeIntProperty"] = info.GetValue<System.Int32>("_someIntProperty");
            _bag["SomeStringProperty"] = info.GetValue<System.String>("_someStringProperty");
        }

Solution 2 - Instead of using a private backing member variable, use 
PropertyInfo (Just like when you set UseMemberVariables to false when 
generating your entities).  Is there a reason that the criteria objects need to 
use a private backing member variable?  Perhaps when you set UseMemberVariables 
to false, it could generate the Criteria objects the same way it generates the 
Entities?

Original issue reported on code.google.com by RoyMunso...@gmail.com on 9 Jun 2010 at 11:11

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 10 Jun 2010 at 2:53

GoogleCodeExporter commented 9 years ago
Ok, so this isn't pretty, but I modified Criteria.Generated.cst to work with 
Solution 1 I proposed above.  I have attached the updated template.  Please 
take a look and let me know what you think.

Original comment by RoyMunso...@gmail.com on 12 Jun 2010 at 12:21

Attachments:

GoogleCodeExporter commented 9 years ago
Hello,

Can you please attach a Silverlight sample application that I can test this 
with.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 15 Jun 2010 at 12:02

GoogleCodeExporter commented 9 years ago
Ok, here you go.  Hopefully this solution works for you, as I can't give you my 
real one.  You will probably have to fix all of the references.  I use CSLA 
beta 2.  Also, I am using modified CSLA templates to handle a few of the 
outstanding issues.  To get it running, you will need to do the same as with 
Rocky's Silverlight demos from the video: Set the web project as the startup 
project (NOT the Silverlight one) and set the SampleTestPage.aspx as the start 
page.

I have included a SqlExpress DB in the web that I used.  I hope this works.  
Seemed to work fine for me in both the app and Codesmith.

If everything works, the app should start and you will see 2 records in a grid. 
 You can put an AddressId in the text box at the top and click the "Get 
Address" Button.  You should see that it doesn't work....you always get all of 
the records (there's only 2).  Then go into AddressCriteria.Generated.cs and 
uncomment my Serialization section.  You should see that it now works 
correctly...it filters based on AddressId.

Let me know if things aren't working and I'll help you out as best as I can.  
Also, please hang on to this solution, as I would like to use it to submit 
further issues.

Thanks,

Original comment by RoyMunso...@gmail.com on 15 Jun 2010 at 3:31

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was updated by revision r1756.

Fixed Issue 398: CSLA - Generated Criteria objects don't work in Silverlight

Original comment by bniemyjski on 28 Jun 2010 at 11:52

GoogleCodeExporter commented 9 years ago
Hello,

Thanks for your samples. I'll hang on to it!!

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 28 Jun 2010 at 11:53