Fluent NHibernate Automap does not count IList <T> collections as indexed

I am using automap to map domain model (simplified version):

public class AppUser : Entity
{
    [Required]
    public virtual string NickName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    public virtual string PassKey { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    public virtual string EmailAddress { get; set; }
    public virtual IList<PreferencesDescription> PreferencesDescriptions { get; set; }
}

public class PreferencesDescription : Entity
{
    public virtual AppUser AppUser { get; set; }
    public virtual string Content{ get; set; }
}

      

The PreferencesDescriptions collection is rendered as an IList, so this is an indexed collection (when I need standard non-indexed collections, I use ICollection).

The point is that free nhibernate hardware devices render my domain model as a single collection (so there is no "position" property in the DDL generated by SchemaExport).

¿How can I do this without having to override this very case - I mean, how can I get the Fluent nhibernate automap to do always indexed collections for IList, but not ICollection

+2


source to share


1 answer


IList is not an indexed collection. You can refer to elements in the IList by index, but their position is not stored in the database. You cannot access the ICollection by index (without using extension methods), but it does have an AddAt method to add an object to the collection by index.



If you need to store the position of objects in the collection, map it as a map , which equates to IDictionary. My guess is that automap will use a map for the IDictionary collection types.

+1


source







All Articles