实体集合属性为空从RavenDB时加载 [英] Entity Collection Property is Empty when Loading from RavenDB
问题描述
我今天开始使用RavenDB。当我保存一个类时,我可以看到在DB集合属性:
然而,当我加载类,集合中有没有项目:
公开的IEnumerable< CustomVariableGroup> GETALL()
{
使用(IDocumentSession会话= Database.OpenSession())
{
IEnumerable的< CustomVariableGroup>组= session.Query< CustomVariableGroup>();
组的回报;
}
}
有一些类型的激活深度,需要以看到设置?是波苏斯属性。
编辑(显示类,按要求):
公共类EntityBase:NotifyPropertyChangedBase
{
公共字符串ID {搞定;组; } //必填字段与RavenDB的所有对象。
}
公共类CustomVariableGroup:EntityBase
{
私人的ObservableCollection< CustomVariable> _customVariables;
公众的ObservableCollection< CustomVariable> CustomVariables
{
得到
{
如果(this._customVariables == NULL)
{
this._customVariables =新的ObservableCollection< CustomVariable>();
}
返回this._customVariables;
}
}
}
公共类CustomVariable:EntityBase
{
私人字符串_key;
私人字符串_value;
///<总结>
///获取或设置键。
///< /总结>
///< VALUE>
///的关键。
///< /值>
公共字符串键
{
{返回this._key; }
组
{
this._key =价值;
NotifyPropertyChanged(()=> this.Key);
}
}
///<总结>
///获取或设置值。
///< /总结>
///< VALUE>
///价值。
///< /值>
公共字符串值
{
{返回this._value; }
组
{
this._value =价值;
NotifyPropertyChanged(()=> THIS.VALUE);
}
}
}
明白了。有一对CustomVariables属性没有setter。当我加入私营制定者,它的工作。因此,显然RavenDB不使用私人支持字段,像db4o的一样。 。RavenDB需要属性
公开的ObservableCollection< CustomVariable> CustomVariables
{
得到
{
如果(this._customVariables == NULL)
{
this._customVariables =新的ObservableCollection< CustomVariable>();
}
返回this._customVariables;
}
私定
{
this._customVariables =价值;
}
}
I started using RavenDB today. When I save a class, I can see the Collection property in the DB:
However, when I load the class, the collection has no items in it:
public IEnumerable<CustomVariableGroup> GetAll()
{
using (IDocumentSession session = Database.OpenSession())
{
IEnumerable<CustomVariableGroup> groups = session.Query<CustomVariableGroup>();
return groups;
}
}
Is there some type of activation depth that needs to be set in order to see the properties that are POCOs?
Edit (to show the classes, by request):
public class EntityBase : NotifyPropertyChangedBase
{
public string Id { get; set; } // Required field for all objects with RavenDB.
}
public class CustomVariableGroup : EntityBase
{
private ObservableCollection<CustomVariable> _customVariables;
public ObservableCollection<CustomVariable> CustomVariables
{
get
{
if (this._customVariables == null)
{
this._customVariables = new ObservableCollection<CustomVariable>();
}
return this._customVariables;
}
}
}
public class CustomVariable : EntityBase
{
private string _key;
private string _value;
/// <summary>
/// Gets or sets the key.
/// </summary>
/// <value>
/// The key.
/// </value>
public string Key
{
get { return this._key; }
set
{
this._key = value;
NotifyPropertyChanged(() => this.Key);
}
}
/// <summary>
/// Gets or sets the value.
/// </summary>
/// <value>
/// The value.
/// </value>
public string Value
{
get { return this._value; }
set
{
this._value = value;
NotifyPropertyChanged(() => this.Value);
}
}
}
Got it. There was no setter on the CustomVariables property. As soon as I added the private setter, it worked. So, apparently RavenDB doesn't use the private backing field, like db4o does. RavenDB needs the property.
public ObservableCollection<CustomVariable> CustomVariables
{
get
{
if (this._customVariables == null)
{
this._customVariables = new ObservableCollection<CustomVariable>();
}
return this._customVariables;
}
private set
{
this._customVariables = value;
}
}
这篇关于实体集合属性为空从RavenDB时加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!