Using CSLA 4.1, SL 4.
I've created a simple ReadOnlyList with two properties. I've got it to load up and work across the dataportal (yea!). As a test I wanted to loop through the items or simply bind them to an listbox.ItemSource. VS complains that it is not an IEnumerable. What gives? Is this not really a list?! It seems like I've missed a step somewhere. Any ideas?
using System;
using System.ComponentModel.DataAnnotations;
using Csla;
using Csla.Serialization;
using System.Diagnostics;
#if !SILVERLIGHT
using System.Data.SqlClient;
#endif
namespace CSLA
{
[Serializable()]
public class CustomerListItem : ReadOnlyBase<CustomerListItem>
{
private static PropertyInfo<int> CustomerIDProperty = RegisterProperty<int>(o => o.CustomerID, "CustomerID");
public int CustomerID
{
get { return GetProperty(CustomerIDProperty); }
set { LoadProperty(CustomerIDProperty, value); }
}
private static PropertyInfo<string> CustomerNameProperty = RegisterProperty<string>(o => o.CustomerName, "CustomerName");
public string CustomerName
{
get { return GetProperty(CustomerNameProperty); }
set { LoadProperty(CustomerNameProperty, value); }
}
public override string ToString()
{
return CustomerName;
}
}
[Serializable()]
public class CustomerList : ReadOnlyListBase<CustomerList, CustomerListItem>
{
#if !SILVERLIGHT
public static CustomerList GetCustomerList()
{
return DataPortal.Fetch<CustomerList>();
}
#endif
public static void GetCustomerList(EventHandler<DataPortalResult<CustomerList>> callback)
{
DataPortal.BeginFetch<CustomerList>(callback);
}
#region Data Access
#if !SILVERLIGHT
private void DataPortal_Fetch()
{
using (SqlCommand sqlcmd = Csla.Data.ConnectionManager<SqlConnection>.GetManager("DB").Connection.CreateCommand())
{
sqlcmd.CommandType = System.Data.CommandType.StoredProcedure;
sqlcmd.CommandText = "fetchCustomers";
sqlcmd.Parameters.AddWithValue("@OperatorID", ((Console.CSLA.ConsoleIdentity)Csla.ApplicationContext.User.Identity).OperatorID);
using (SqlDataReader sqldr = sqlcmd.ExecuteReader())
{
IsReadOnly = false;
while (sqldr.Read())
{
this.Add(new CustomerListItem()
{
CustomerID = sqldr.GetInt32(sqldr.GetOrdinal("CustomerID")),
CustomerName = sqldr.GetString(sqldr.GetOrdinal("CustomerName"))
}
);
}
IsReadOnly = true;
}
}
}
#endif
#endregion
}
}
I don't know. The only thing I can think of, is that if your test was using LINQ that you are missing the 'using System.Linq' statement.
Hi,
maybe this is related to a breaking change from .NET 3.5 to .NET 4, mentioned by Frans Bouma here...
Copyright (c) Marimer LLC