I'm using the CSLA.NET 3.5.1 version. I tried changing the RoleList class from Project Tracker to point to my database roles table which uses a Guid for the RoleId instead of integer. When I use the following code in my class I get a InvalidCastException
Unable to cast object of type 'System.Collections.Generic.List`1[Csla.NameValueListBase`2+NameValuePair[System.Int32,System.String]]' to type 'System.Collections.Generic.IList`1[Csla.NameValueListBase`2+NameValuePair[System.Guid,System.String]]'.
using Csla;
using Csla.Data;
using System;
using System.Linq;
namespace ProjectTracker.Library
{
[Serializable()]
public class RoleList : NameValueListBase<Guid, string>
{
#region Business Methods
public static Guid DefaultRole()
{
RoleList list = GetList();
if (list.Count > 0)
return list.Items[0].Key;
else
throw new NullReferenceException("No roles available; default role can not be returned");
}
#endregion
#region Factory Methods
private static RoleList _list;
public static RoleList GetList()
{
if (_list == null)
_list = DataPortal.Fetch<RoleList>();
return _list;
}
/// <summary>
/// Clears the in-memory RoleList cache
/// so the list of roles is reloaded on
/// next request.
/// </summary>
public static void InvalidateCache()
{
_list = null;
}
private RoleList()
{ /* require use of factory methods */ }
#endregion
#region Data Access
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
using (var ctx = ContextManager<ProjectTracker.DalLinq.AspNetDbDataContext>.GetManager(ProjectTracker.DalLinq.Database.AspNetDb))
{
var data = from role in ctx.DataContext.aspnet_Roles
select new NameValuePair(role.RoleId, role.RoleName);
IsReadOnly = false;
this.AddRange(data);
IsReadOnly = true;
}
this.RaiseListChangedEvents = true;
}
#endregion
}
}
Any help on this matter would be greatly appreciated.
Thanks,
Kent