Csla.NameValueListBase - Insert is an invalid operation

Csla.NameValueListBase - Insert is an invalid operation

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


decius posted on Wednesday, March 11, 2009

On a NameValueListBase class I've made, I'm throwing the "Insert is an invalid operation" in the DataPortal_Fetch.  I've set RaiseChangedEvents to false before calling the Add operation.  I'm starting to wonder if it has something to do with the Generic I'm also using in my class.  I'm sort of trying something a little different here...  Can this work? I don't see why it wouldn't...

[Serializable()]

public class NewStatusCountsInfo<T> : Csla.NameValueListBase<T, int>

{

private NewStatusCountsInfo()

{ /* require use of factory method */}

internal static NewStatusCountsInfo<T> GetNewStatusCountsInfo(SafeDataReader dr)

{

return DataPortal.Fetch<NewStatusCountsInfo<T>>(dr);

}

[RunLocal()]

private void DataPortal_Fetch(SafeDataReader dr)

{

this.RaiseListChangedEvents = false;

Fetch(dr);

this.RaiseListChangedEvents = true;

}

private void Fetch(SafeDataReader dr)

{

while (dr.Read())

this.Add(new NameValuePair((T)(dr["Status"]), dr.GetInt32("Total")));

}

}

decius replied on Wednesday, March 11, 2009

PS. Originally I didn't bother with even using the DataPortal at all, but I assumed that maybe by not using it I was somehow still getting the RaiseChangedEvents to occur... So I tried a RunLocal() and got the same results.

ajj3085 replied on Wednesday, March 11, 2009

You need to set IsReadOnly before add items, and set it back to false before your DataPortal_Fetch returns.

decius replied on Wednesday, March 11, 2009

DOH!  thanks so much, I guess I didn't anticipate NameValueListBase behaving like a ReadOnlyBase.  Thanks again!

Copyright (c) Marimer LLC