Execute command doesnt use the wanted constructor on server side when using Async Command

Execute command doesnt use the wanted constructor on server side when using Async Command

Old forum URL: forums.lhotka.net/forums/t/9655.aspx


emadalsous posted on Tuesday, October 19, 2010

Hello, iam using Silverlight4 with csla 4.0 .

ihave command where it checks exists in Database

iam using async with the rule where it call the command from the server side

the command has constructor with parameter where it set the condition for check

on SL client side every thing work fine . but on .Net Server side the constructor with parameters

doesnt be executed . the used constructor is the default constructor

What Should i be missing here, this is my command code :

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

[

 

 

Serializable

]

 

 

 

 

 

 

public class ExsistCurrncyName : CommandBase<ExsistCurrncyName>

{

ExsistCurrncyName()

{ }

 

 

 

 

string  _currncyName;

 

 

 

 

 

 

 

public bool CurrncyExsist { get; private set

; }

 

 

 

 

#if

 

 

 

!SILVERLIGHT

 

 

 

public static bool IsExsist(string currncyName)

{

 

 

 

var result = DataPortal.Execute<ExsistCurrncyName>(new ExsistCurrncyName(currncyName));

 

 

 

return

result.CurrncyExsist;

}

 

#endif

 

 

 

 

public ExsistCurrncyName(string

 currname)

{

 

CurrncyExsist =

 

 

false

;

_currncyName = currname;

}

 

#if

 

 

 

 

!SILVERLIGHT

 

 

 

protected override void

DataPortal_Execute()

{

 

 

 

using (var ctx = new EFData.GeneralAccountDBEntities())

{

CurrncyExsist = ((

 

 

 

from cr in ctx.Currencies where cr.CurrencyName.ToLower() == this._currncyName.ToLower()

 

 

 

 

 

select cr).Count() > 0);

}

}

 

 

#endif

}

 

RockfordLhotka replied on Tuesday, October 19, 2010

A command is a mobile object, just like any other business object. If you don't use managed backing fields, you must manually serialize your fields. If you don't serialize a private field value, it won't flow across the wire through the data portal.

The simplest thing to do is to use managed properties.

In any case, when the object deserializes on the server the MobileFormatter will use the default constructor. That's just the way deserialization works. The server-side object is a clone of the client-side object, and its state should be set by the deserialization process, not by the constructor.

Copyright (c) Marimer LLC