static bool IsSet(Member member) { return member.PropertyType == typeof(ISet) || member.PropertyType.Closes(typeof(ISet<>)) || member.PropertyType.Closes(typeof(HashSet<>)); } static bool IsEnumerable(Member member) { return member.PropertyType == typeof(IEnumerable) || member.PropertyType.Closes(typeof(IEnumerable<>)); }
public override Action<T, Accessor, IEnumerable<TListElement>> ValueSetter { get { if (_valueSetter != null) { return _valueSetter; } return (target, propertyAccessor, value) => { object collection; // sorry guys - create an instance of the collection type because we can't rely // on the user to pass in the correct collection type (especially if they're using // an interface). I've tried to create the common ones, but I'm sure this won't be // infallible. if (propertyAccessor.PropertyType.IsAssignableFrom(typeof(ISet<TListElement>))) { collection = new HashedSet<TListElement>(Expected.ToList()); } else if (propertyAccessor.PropertyType.IsAssignableFrom(typeof(ISet))) { collection = new HashedSet((ICollection)Expected); } else if (propertyAccessor.PropertyType.IsArray) { collection = Array.CreateInstance(typeof(TListElement), Expected.Count()); Array.Copy((Array)Expected, (Array)collection, Expected.Count()); } else { collection = new List<TListElement>(Expected); } propertyAccessor.SetValue(target, collection); }; } set { _valueSetter = value; } }
Modt Ragrds,
--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.
public class Product : EntityBase { private readonly HashSet<Customization> customizations; public Product() { customizations = new HashSet<Customization>(); } public virtual string Name { get; set; } public virtual decimal Price { get; set; } public virtual HashSet<Customization> Customizations { get { return customizations; } } } public class Customization : EntityBase { private readonly HashSet<string> possibleValues; public Customization() { possibleValues = new HashSet<string>(); } public virtual string Name { get; set; } public virtual HashSet<string> PossibleValues { get { return possibleValues; } } }
<set access="nosetter.lowercase" cascade="all" name="Customizations"> <key> <column name="Product_id" /> </key> <one-to-many class="FluentNHSampleApp.Domain.Customization, FluentNHSampleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> </set>
using (ITransaction tx = s.BeginTransaction()) { var product = new Product { Name = "Fideos", Customizations = { new Customization { Name = "Tuco", PossibleValues = {"Pocon", "Medio", "Sopa"} } } }; s.Save(product); tx.Commit(); }
Any ideas? Thanks again.
--
Regards,
Ugh, that's not good. Sorry Mohamed, but it doesn't look like there's going to be an easy way to get this to work without using Iesi.Collections. I'll get a fix out ASAP to get it working with the native .Net 4 collection types, no hackery required.
--
Thanks,
For what it's worth, you're not the only one who's requested native ISet support either.
--
Thanks a lot James,
Regards.
v1.x branch now should have a fix for this. Because we're not a .Net for project yet (and I can't yet be bothered to maintain two versions), FNH will just pick up any type named ISet<T> and assume you know what you're doing. Let me know how it turns out when you've had a chance to take a look.
--
I also just realised I said ".Net for" instead of ".Net 4"... Can you tell I was working late last night? ;)
--
Thanks a lot, James.Worked great in my sample app.Waiting for the Nuget update to include it in the post.Thanks again,Regards,
On Fri, May 13, 2011 at 6:13 PM, James Gregory <jagregory.com@gmail.com> wrote:
I also just realised I said ".Net for" instead of ".Net 4"... Can you tell I was working late last night? ;)
--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibernate+unsubscribe@googlegroups.com.