问题
In Fluent Nhibernate what is the effect of specifying AsSet() on a HasMany or HasManyToMany relationship?
Assuming the type of the mapped property is an Iesi Set, is there any difference between:
HasMany(x => x.MySetProperty)
.AsSet();
and
HasMany(x => x.MySetProperty);
回答1:
Assuming your type is an Iesi Set, then there's no difference; the HasMany call on it's own is smart enough to figure out that you want a Set. The AsSet is a way to explicitly change your HasMany to a Set in situations where FNH might not be able to determine it by type, for example if you're exposing your collection as an IEnumerable it would default to a Bag and calling AsSet would override that.
来源:https://stackoverflow.com/questions/2054076/fluentnhibernate-what-is-the-effect-of-asset