It would seem as if the general answer is that you can't "cascade
Refresh" a collection. And that the "cascade" option should exclude
this.
I've written the following code, and it seems to work just fine to
prepare a collection for a "cascade" refresh:
private void RemoveTransientsFromList(IList list)
{
if (list == null || list.Count == 0) return;
var i = 0;
while (i < list.Count)
{
var metaData = (IEntityPersister)
Session.SessionFactory.GetClassMetadata(list[0].GetType());
if (metaData.IsTransient(list[i],
Session.GetSessionImplementation()) == true)
list.RemoveAt(i);
else
i++;
}
}
public void Refresh(T entity)
{
var metadata = Session.SessionFactory.GetClassMetadata
(entity.GetType());
var propertyValues = metadata.GetPropertyValues(entity,
EntityMode.Poco);
var propertyTypes = metadata.PropertyTypes;
for (var i = 0; i < propertyTypes.Length; i++)
{
if (propertyTypes[i].IsCollectionType)
RemoveTransientsFromList((IList)propertyValues[i]);
}
Session.Refresh(entity);
}
Comments? Suggestion?
Thanks,
Dawid