Hi all
I am writing a silverlight app using CLSA 3.6.
I have recoded the templates for CLSAGen to create the correct files as required.
However I am having a bit of an issue with the criteria class. I have created a class as detailed in the book.
[
Serializable()]}
protected void DataPortal_Fetch(CriteriaSystemUser crit)
{
using (SqlConnection cn = new SqlConnection(DataBase.MakingSpaceOperationsConnection))
{
using (SqlCommand cmd = cn.CreateCommand())
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "JM_ServiceCentre_ListBySystemUser";
cmd.Parameters.AddWithValue("@USR_Login", crit.USR_Login);
.........
But If i run this I get a no parameterless constructor defined for this object error
So I then add a constructor
private CriteriaSystemUser():
base(typeof(CriteriaSystemUser)){
}
which now runs succesfully but although the USR_Login value gets set in the class. It is not passed through to the dataportal fetch
Any ideas would be most helpful, I have gone back to using the singlecriteria which works fine for now.
Cheers
Daniel
Any CSLA class in SL must have a public parameterless
constructor. There are no exceptions to this rule, including criteria
classes. This requirement stems out of reflection restrictions in
Silverlight.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: danielw
[mailto:cslanet@lhotka.net]
Sent: Tuesday, January 13, 2009 8:33 AM
To: Sergey Barskiy
Subject: [CSLA .NET] Criteria Class with Silverlight CSLA 3.6
Hi all
I am writing a silverlight app using CLSA 3.6.
I have recoded the templates for CLSAGen to create the correct files as
required.
However I am having a bit of an issue with the criteria class. I have
created a class as detailed in the book.
[Serializable()]
protected class
CriteriaSystemUser : CriteriaBase
{
private string
_USR_Login;
public string USR_Login {
get { return _USR_Login; }
}
public CriteriaSystemUser(String uSR_Login)
:base(typeof(CriteriaSystemUser))
{
_USR_Login = uSR_Login;
}
}
protected void DataPortal_Fetch(CriteriaSystemUser crit)
{
using (SqlConnection cn = new
SqlConnection(DataBase.MakingSpaceOperationsConnection))
{
using (SqlCommand cmd = cn.CreateCommand())
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "JM_ServiceCentre_ListBySystemUser";
cmd.Parameters.AddWithValue("@USR_Login", crit.USR_Login);
.........
But If i run this I
get a no parameterless
constructor defined for this object error
So I then add a
constructor
private CriteriaSystemUser()
:base(typeof(CriteriaSystemUser))
{
}
which now runs
succesfully but although the USR_Login value gets set in the class. It is not
passed through to the dataportal fetch
Any ideas would be
most helpful, I have gone back to using the singlecriteria which works fine for
now.
Cheers
Daniel
Thanks for that
I have changed the constructor to public . But I still can not get access to the passed in value in my Fetch procedure
protected void DataPortal_Fetch(CriteriaSystemUser crit)
{
using (SqlConnection cn = new SqlConnection(DataBase.MakingSpaceOperationsConnection))
{
using (SqlCommand cmd = cn.CreateCommand())
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "JM_ServiceCentre_ListBySystemUser";
cmd.Parameters.AddWithValue("@USR_Login", crit.USR_Login);
The Crit.USR_Login is blank
Cheers
Daniel
Alternatively, you can inherit from CriteriaBase and use
RegisterProperty syntax to register custom properties. This method is probably
more consistent with other CSLA classes.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: PeteH
[mailto:cslanet@lhotka.net]
Sent: Tuesday, January 13, 2009 10:46 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Criteria Class with Silverlight CSLA 3.6
You
will need to add these lines to the client version of CriteriaSystemUser.
#region MobileFormatter
/// <summary>
/// Override this method to insert your field
values
/// into the MobileFormatter serialzation
stream.
/// </summary>
/// <param name="info">
/// Object containing the data to serialize.
/// </param>
/// <param name="mode">
/// The StateMode indicating why this method was
invoked.
/// </param&a mp;gt;
protected override void
OnGetState(SerializationInfo info, StateMode mode)
{
base.OnGetState(info, mode);
info.AddValue("Csla.Silverlight.</font></font><font
face="Tahoma"><font
size="2">CriteriaSystemUser</font></font><font
face="Tahoma"><font size="2">._USR_Login",
_USR_Login);
</font></font><font face="Tahoma"><font
size="2"> }
/// <summary>
/// Override this method to retrieve your field
values
/// from the MobileFormatter serialzation
stream.
/// & amp;lt;/summary>
/// <param name="info">
/// Object containing the data to serialize.
/// </param>
/// <param name="mode">
/// The StateMode indicating why this method was
invoked.
/// </param>
protected override void OnSetState(SerializationInfo
info, StateMode mode)
{
base.OnSetState(info, mode);
_</font></font><font face="Tahoma"><font
size="2">_USR_Login </font></font><font
face="Tahoma"><font size="2">= info.G
etValue<int>("Csla.Silverlight.</font></font><font
face="Tahoma"><font
size="2">CriteriaSystemUser</font></font><font
face="Tahoma"><font size="2">._USR_Login");
}
#endregion
Sorry not sure if I am being stupid,
But i have added the code as suggested but I still do not get the value back.
Do I need to call some other method than crit.USR_Login to get the value
protected void DataPortal_Fetch(CriteriaSystemUser crit)
cheers
Daniel
Thanks for your help
could not get it to work using the override methods of mobile.
And also could not registerpropertys in the CriteriaBase.
But I took this idea and created a BusinessBase as a criteria as in the book, I could then register the properties and it now works beautifully with the CSLA gen
Cheers
daniel
Daniel,
Could you post code to help me out with same issue?
Cheers
Terry
Here is an example of how to use Criteria class for Silverlight
inheriting from CriteriaBase. This specific class is embedded inside a
ROLB class, but you can have it as external / stand alone class as well.
[Serializable]
public class Criteria : CriteriaBase
{
private static PropertyInfo<string>
SearchProperty = RegisterProperty<string>(typeof(Criteria), new PropertyInfo<string>("Search",
"Search"));
public string
Search
{
get { return
ReadProperty(SearchProperty); }
}
private static PropertyInfo<bool>
IncludeAddressProperty = RegisterProperty<bool>(typeof(Criteria), new PropertyInfo<bool>("IncludeAddress",
"IncludeAddress"));
public bool
IncludeAddress
{
get { return
ReadProperty(IncludeAddressProperty); }
}
public Criteria(Type
type, string search, bool
includeAddress)
: base(type)
{
LoadProperty(SearchProperty, search);
LoadProperty(IncludeAddressProperty, includeAddress);
}
public Criteria() { }
}
Here
is how to use it:
public static void GetReadonlySearchedPersonList(string search, bool
includeAddress, EventHandler<DataPortalResult<ReadonlySearchedPersonList>>
handler)
{
DataPortal<ReadonlySearchedPersonList>
dp = new DataPortal<ReadonlySearchedPersonList>();
dp.FetchCompleted += handler;
dp.BeginFetch((new Criteria(typeof(ReadonlySearchedPersonList),
search, includeAddress)));
}
private void DataPortal_Fetch(Criteria
criteria)
{
….
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: thunt
[mailto:cslanet@lhotka.net]
Sent: Monday, January 19, 2009 8:50 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Criteria Class with Silverlight CSLA 3.6
Daniel,
Could you post code to help me out with same issue?
Cheers
Terry
Hi Terry,
Using a business base I did it like this.
[
Serializable()]}
with the call being
public static void DeleteMedicalContact(Int32 mED_ID,EventHandler<DataPortalResult<MedicalContact>> handler)cheers
Daniel
Copyright (c) Marimer LLC