Value cannot be null. Parameter name: key (CSLA Light)

Value cannot be null. Parameter name: key (CSLA Light)

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


CampbellCM posted on Friday, May 01, 2009

I'm getting this error when I try to delete a BO.

Here is the DataPortal_Delete method:

[Transactional(TransactionalTypes.TransactionScope)]
protected void DataPortal_Delete(ProfileCriteria criteria)
{
...
}

Here is the SL factory method:

public static void DeleteProfile(string profileID, string companyID, EventHandler> handler)
{
DataPortal dp = new DataPortal();
dp.DeleteCompleted += handler;
ProfileCriteria criteria = new ProfileCriteria();
criteria.ProfileID = profileID;
criteria.CompanyID = companyID;
dp.BeginDelete(criteria);
}

Here is the criteria class:

[Serializable]
public class ProfileCriteria : BusinessBase
{

private static PropertyInfo ProfileIDProperty = RegisterProperty
(
typeof(ProfileCriteria), new PropertyInfo("ProfileID", "ProfileID")
);

public string ProfileID
{
get
{
return GetProperty(ProfileIDProperty);
}
set
{
SetProperty(ProfileIDProperty, value);
}
}

private static PropertyInfo CompanyIDProperty = RegisterProperty
(
typeof(ProfileCriteria), new PropertyInfo("CompanyID", "CompanyID")
);

public string CompanyID
{
get
{
return GetProperty(CompanyIDProperty);
}
set
{
SetProperty(CompanyIDProperty, value);
}
}

}

I use the same methodology for the DataPortalFetch method (including the criteria class), no problem.

Any ideas?

CampbellCM replied on Friday, May 01, 2009

After searching the forum again I found what appeared to be a related post and tried a couple of things suggested there. First I tried implementing the ICriteria interface on my criteria BO and that didn't work. I then tried inheriting my criteria class from CriteriaBase and that did the trick. It seems odd to me that the BusinessBase derived criteria class works with DataPortal_Fetch and not the DataPortal_Delete...

RockfordLhotka replied on Friday, May 01, 2009

Implementing ICriteria should have done the trick, as long as you returned the correct business object type through the ICriteria interface.

The data portal now has three models for finding the type of the business object.

  1. If the data portal method call is generic (like Delete<T>()) then T is used
  2. If the criteria object implements ICriteria, then the type returned by ICriteria is used
  3. If the criteria class is nested in the business class, then the type containing the criteria class is used

These models should follow that order of preference.

Copyright (c) Marimer LLC