views:

275

answers:

1

I am using automap to map a 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 mapped as an IList, so is an indexed collection (when I require standard unindexed collections I use ICollection).

The fact is that fluent nhibernate's automap facilities map my domain model as an unindexed collection (so there's no "position" property in the DDL generated by SchemaExport).

¿How can I make it without having to override this very case - I mean, how can I make Fluent nhibernate's automap make always indexed collections for IList but not for ICollection

+2  A: 

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

If you need to store an objects position in the collection, map it as a map which equates to an IDictionary. I assume the automap will use map for a IDictionary collection types.

Jamie Ide
In NHibernate you can map an indexed collection to an IList. Anyway, thankyou.
Francisco Lozano