Hi,
I am binding to a grid in Silver light using the following:
<csla:CslaDataProvider x:Key="ExpensesData"
ManageObjectLifetime="True"
IsInitialLoadEnabled="True"
ObjectType="XXX.ReadOnlyExpenseList, XXX, Version=..., Culture=neutral, PublicKeyToken=null"
PropertyChanged="CslaDataProvider_PropertyChanged"
DataChanged="CslaDataProvider_DataChanged"
FactoryMethod="GetExpenseList"/>
It appears that LoadProperty<> returns default value not value from DataReader for all properties except the SafeDateTime. Can anyone see my error?
Thanks in advance.
READONLYLIST
+++++++++++++++
[Serializable]
public class ReadOnlyExpenseList : ReadOnlyListBase<ReadOnlyExpenseList, ReadOnlyExpense>
{
#if SILVERLIGHT
public ReadOnlyExpenseList() {}
#else
private ReadOnlyExpenseList() { }
#endif
public static void GetExpenseList(EventHandler<DataPortalResult<ReadOnlyExpenseList>> handler)
{
DataPortal<ReadOnlyExpenseList> dp = new DataPortal<ReadOnlyExpenseList>();
dp.FetchCompleted += handler;
dp.BeginFetch();
}
#if !SILVERLIGHT
private void DataPortal_Fetch()
{
RaiseListChangedEvents = false;
IsReadOnly = false;
using(SqlConnection connection = new SqlConnection(DataConnection.ConnectionString))
{
connection.Open();
using(SqlCommand command = new SqlCommand("GetExpenses", connection))
{
command.CommandType = System.Data.CommandType.StoredProcedure;
using(Csla.Data.SafeDataReader reader = new SafeDataReader(command.ExecuteReader()))
{
while (reader.Read())
{
Add(ReadOnlyExpense.GetReadOnlyExpense(reader));
}
}
}
connection.Close();
}
IsReadOnly = true;
RaiseListChangedEvents = true;
}
#endif
READONLY BO
+++++++++++++
[Serializable]
public class ReadOnlyExpense : ReadOnlyBase<ReadOnlyExpense>
{
#if SILVERLIGHT
public ReadOnlyExpense() { }
#else
private ReadOnlyExpense() { }
#endif
private static PropertyInfo<int> ExpenseIdProperty = RegisterProperty<int>(new PropertyInfo<int>("ExpenseId", "Expense Id", 0));
public int ExpenseId
{
get
{
return GetProperty(ExpenseIdProperty);
}
}
private static PropertyInfo<SmartDate> ExpenseDateProperty = RegisterProperty<SmartDate>(new PropertyInfo<SmartDate>("ExpenseDate", "Expense Date", DateTime.Today));
public SmartDate ExpenseDate
{
get
{
return GetProperty(ExpenseDateProperty);
}
}
private static PropertyInfo<string> ClientNameProperty = RegisterProperty<string>(new PropertyInfo<string>("ClientName", "Client Name", string.Empty));
public string ClientName
{
get
{
return GetProperty(ClientNameProperty);
}
}
private static PropertyInfo<string> LocationProperty = RegisterProperty<string>(new PropertyInfo<string>("Location", "Location", string.Empty));
public string Location
{
get
{
return GetProperty(LocationProperty);
}
}
private static PropertyInfo<int> CategoryIdProperty = RegisterProperty<int>(new PropertyInfo<int>("CategoryId", "Category Id", 0));
public int CategoryId
{
get
{
return GetProperty(CategoryIdProperty);
}
}
private static PropertyInfo<int> CallReasonIdProperty = RegisterProperty<int>(new PropertyInfo<int>("CallReasonId", "CallReason Id", 0));
public int CallReasonId
{
get
{
return GetProperty(CallReasonIdProperty);
}
}
private static PropertyInfo<decimal> NetPremiumQuotedProperty = RegisterProperty<decimal>(new PropertyInfo<decimal>("NetPremiumQuoted", "Net Premium Quoted", 0));
public decimal NetPremiumQuoted
{
get
{
return GetProperty(NetPremiumQuotedProperty);
}
}
private static PropertyInfo<decimal> RenewalChargeProperty = RegisterProperty<decimal>(new PropertyInfo<decimal>("RenewalCharge", "Renewal Charge", 0));
public decimal RenewalCharge
{
get
{
return GetProperty(RenewalChargeProperty);
}
}
private static PropertyInfo<int> OutcomeIdProperty = RegisterProperty<int>(new PropertyInfo<int>("OutcomeId", "Outcome Id", 0));
public int OutcomeId
{
get
{
return GetProperty(OutcomeIdProperty);
}
}
private static PropertyInfo<int> CompetitionIdProperty = RegisterProperty<int>(new PropertyInfo<int>("CompetitionId", "Competition Id", 0));
public int CompetitionId
{
get
{
return GetProperty(CompetitionIdProperty);
}
}
private static PropertyInfo<decimal> CompetingQuoteProperty = RegisterProperty<decimal>(new PropertyInfo<decimal>("CompetingQuote", "Competing Quote", 0));
public decimal CompetingQuote
{
get
{
return GetProperty(CompetingQuoteProperty);
}
}
private static PropertyInfo<int> MileageProperty = RegisterProperty<int>(new PropertyInfo<int>("Mileage", "Mileage", 0));
public int Mileage
{
get
{
return GetProperty(MileageProperty);
}
}
private static PropertyInfo<int> MileageReasonIdProperty = RegisterProperty<int>(new PropertyInfo<int>("MileageReasonId", "Mileage Reason Id", 0));
public int MileageReasonId
{
get
{
return GetProperty(MileageReasonIdProperty);
}
}
protected override void AddAuthorizationRules()
{
string[] canRead = new string[] { "AdminUser", "RegularUser", "ReadOnlyUser" };
//AuthorizationRules.AllowGet(typeof(Company), canRead);
AuthorizationRules.AllowRead(ExpenseIdProperty, canRead);
AuthorizationRules.AllowRead(ClientNameProperty, canRead);
AuthorizationRules.AllowRead(LocationProperty, canRead);
AuthorizationRules.AllowRead(CategoryIdProperty, canRead);
AuthorizationRules.AllowRead(CallReasonIdProperty, canRead);
AuthorizationRules.AllowRead(NetPremiumQuotedProperty, canRead);
AuthorizationRules.AllowRead(RenewalChargeProperty, canRead);
AuthorizationRules.AllowRead(OutcomeIdProperty, canRead);
AuthorizationRules.AllowRead(CompetitionIdProperty, canRead);
AuthorizationRules.AllowRead(CompetingQuoteProperty, canRead);
AuthorizationRules.AllowRead(MileageProperty, canRead);
AuthorizationRules.AllowRead(MileageReasonIdProperty, canRead);
}
#if !SILVERLIGHT
public static ReadOnlyExpense GetReadOnlyExpense(SafeDataReader reader)
{
return DataPortal.FetchChild<ReadOnlyExpense>(reader);
}
private void Child_Fetch(SafeDataReader reader)
{
LoadProperty<int>(ExpenseIdProperty, reader.GetInt32("ExpenseId"));
LoadProperty<SmartDate>(ExpenseDateProperty, reader.GetSmartDate("ExpenseDate"));
LoadProperty<string>(ClientNameProperty, reader.GetString("ClientName"));
LoadProperty<string>(LocationProperty, reader.GetString("Location"));
LoadProperty<int>(CategoryIdProperty, reader.GetInt32("CategoryId"));
LoadProperty<int>(CallReasonIdProperty, reader.GetInt32("CallReasonId"));
LoadProperty<decimal>(NetPremiumQuotedProperty, reader.GetDecimal("NetPremiumQuoted"));
LoadProperty<decimal>(RenewalChargeProperty, reader.GetDecimal("RenewalCharge"));
LoadProperty<int>(OutcomeIdProperty, reader.GetInt32("OutcomeId"));
LoadProperty<int>(CompetitionIdProperty, reader.GetInt32("CompetitionId"));
LoadProperty<decimal>(CompetingQuoteProperty, reader.GetDecimal("CompetingQuote"));
LoadProperty<int>(MileageProperty, reader.GetInt32("Mileage"));
LoadProperty<int>(MileageReasonIdProperty, reader.GetInt32("MileageReasonId"));
}
#endif
You can't pass a datareader through the DataPortal.
public static ReadOnlyExpense GetReadOnlyExpense(SafeDataReader reader)
{
return DataPortal.FetchChild<ReadOnlyExpense>(reader);
}
When filling a child object with a datareader you call internal methods and pass the reader directly to them.
Joe
Thanks for the reply. I'm new so please bear with me...
I got the code from the Rolodex example which seems to be doing the same as mine. I don't get any errors or warnings about sending a datareader, just default values for most of the properties.
Copyright (c) Marimer LLC