CSLA Light: Is it possible to send a Business Base class as a criteria object

CSLA Light: Is it possible to send a Business Base class as a criteria object

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


starwar46 posted on Monday, August 31, 2009

Hi there,

Your help is needed, I am trying to pass a Business Base class(Customer) as a criteria to fetch another entity(Order), there are some properties on Customer which I want to make use of while querying for Order. I have written the code by following some leads on forum but I am getting error:

public class NwndSingleCriteria : CriteriaBase
where C : BusinessBase
{
private static PropertyInfo NwndBusinessProperty = RegisterProperty(typeof(NwndSingleCriteria), new PropertyInfo("NwndBusiness", "Business Entity"));
public C NwndBusiness
{
get { return ReadProperty(NwndBusinessProperty); }
}

public NwndSingleCriteria(C value)
: base(typeof(B))
{
LoadProperty(NwndBusinessProperty, value);
}

#if SILVERLIGHT

{ }
#else
protected NwndSingleCriteria()
{ }
#endif

#region MobileFormatter


protected override void OnGetState(SerializationInfo info, StateMode mode)
{
base.OnGetState(info, mode);
info.AddValue("Nwnd.Business.Base._value", NwndBusiness);
}

protected override void OnSetState(SerializationInfo info, StateMode mode)
{
base.OnSetState(info, mode);
//NwndBusiness = info.GetValue("Nwnd.Business.Base._value");
}

#endregion

the error that I am getting is:

Message="Type 'Nwnd.Business.Customer' with data contract name 'Customer:http://schemas.datacontract.org/2004/07/Nwnd.Business' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer."


Please let me know if thats even possible?

Thanks

sergeyb replied on Monday, August 31, 2009

I have done something similar, but I did not use CriteriaBase. Simply have your BB object that you use as criteria and just pass it along to dp.BeginFetch()

Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

-----Original Message-----
From: starwar46 [mailto:cslanet@lhotka.net]
Sent: Monday, August 31, 2009 1:40 PM
To: Sergey Barskiy
Subject: [CSLA .NET] CSLA Light: Is it possible to send a Business Base class as a criteria object

Hi there,

Your help is needed, I am trying to pass a Business Base class(Customer) as a criteria to fetch another entity(Order), there are some properties on Customer which I want to make use of while querying for Order. I have written the code by following some leads on forum but I am getting error:

public class NwndSingleCriteria : CriteriaBase
where C : BusinessBase
{
private static PropertyInfo NwndBusinessProperty = RegisterProperty(typeof(NwndSingleCriteria), new PropertyInfo("NwndBusiness", "Business Entity"));
public C NwndBusiness
{
get { return ReadProperty(NwndBusinessProperty); }
}

public NwndSingleCriteria(C value)
: base(typeof(B))
{
LoadProperty(NwndBusinessProperty, value);
}

#if SILVERLIGHT

{ }
#else
protected NwndSingleCriteria()
{ }
#endif

#region MobileFormatter


protected override void OnGetState(SerializationInfo info, StateMode mode)
{
base.OnGetState(info, mode);
info.AddValue("Nwnd.Business.Base._value", NwndBusiness);
}

protected override void OnSetState(SerializationInfo info, StateMode mode)
{
base.OnSetState(info, mode);
//NwndBusiness = info.GetValue("Nwnd.Business.Base._value");
}

#endregion

the error that I am getting is:

Message="Type 'Nwnd.Business.Customer' with data contract name 'Customer:http://schemas.datacontract.org/2004/07/Nwnd.Business' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer."


Please let me know if thats even possible?

Thanks

RockfordLhotka replied on Monday, August 31, 2009

I believe you need to implement ICriteria as well, otherwise BusinessBase<T> should work fine as a criteria object.

starwar46 replied on Monday, August 31, 2009

hey thanks, that was so simple.

Copyright (c) Marimer LLC