Я совершил простую ошибку. Я не добавлял данные к целевому фрейму данных, а скорее к новому weighted_t, что означало, что фрейм данных не был сохранен. Это простое исправление. Спасибо всем, кто пытался помочь.
for i in range(df.shape[0]):
weighted_df = weighted_df.append(weighted_rows(i), ignore_index=True)
Опция On - создать собственную реализацию CustomList, которая является оберткой вокруг экземпляра, реализующего IList
, т. Е .:
public CustomList<AnotherObject> Items
{
return new CustomList<AnotherObject>(items);
}
, т.е. когда вы добавляете в свой CustomList
он добавляет в список поддержки.
Похоже, что пока ваш класс реализует IList
, а также IList
, у вас все будет хорошо.
Yes, unfortunately you can't go about it this way. Calling ToList()
creates a brand new instance of the list, so when you add items to that instance they aren't going to be reflected in the original list (as you've clearly discovered).
I don't use NHibernate, but I would be curious to see if your container implements IList
(the non-generic version). From the thread you referenced, it appears that System.Collections.IList
is what's actually required (and that's implemented by List
, which is why it works). Does your container implement IList
?
Не могли бы вы просто разыграть это так?
public class MyObject
{
private IList<AnotherObject> items;
public List<AnotherObject> Items()
{
return (List<AnotherObject>)items;
}
}
Разве не хватило шанса попробовать это, но я думаю, что это должно сработать!
Я думаю, что коллекция NHibernate PersistentBag (неуниверсальная) реализует IList
, поэтому вы можете печатать элементы как IList
вместо IList
. Ссылка в вашем вопросе гласит, что проблема в том, что для репликатора требуется IList, который реализует List
, а IList
- нет (см. Рисунок).
Можно ли привести его к IEnumerable
public class MyObject
{
private IList<AnotherObject> items;
public List<AnotherObject> Items
{
return new List<AnotherObject>items.Cast<AnotherObject>());
}
// or, to prevent modifying the list
public IEnumerable<AnotherObject> Items
{
return items.Cast<AnotherObject>();
}
}