I have the following in my NHibernate entity:
private ICollection<string> _stringSet = new HashSet<string>();
public virtual ICollection<string> StringSet
{
get { return _stringSet; }
}
Then, in my Fluent mapping I map it like so:
HasMany(x => x.StringSet)
.Table("String_Set")
.Element("StringValue")
.AsSet();
Unfortunately, when I try to save the entity, I get an ArgumentNullException
saying the "Collection cannot be null." I do not get this error if I default my field to a List, but as you see in my mapping, I want Set behavior, even from an unsaved entity. It appears to me to be a problem with HashSet<>
not implementing the non-generic ICollection
. What is the proper way to have Set behavior for unsaved entities? I would also prefer to retain the ICollection<string>
as my exposed type.